简体   繁体   中英

Estimating Coefficients of Multiple Regression

I have the following problem:

I'm using the data "Railtrail" from this library "mosaicData". I already have the coeffiecient of this following linear regression model: lm(volume ~ hightemp + cloudcover + weekday, data = RailTrail) , compute for the population.

Now, I need to estimate the coeffiecient of that model with samples and to build a confidence interval (95%). So I need to compute all the coefficients of the data samples previously generated. I was asked to use a loop 'for' but I don't know how to compute the LR models. I also need to store the coefficient obtained.

I tried to do it doing this

trial <- list()
set.seed(101)

for(i in 1:100){
  trial[[i]] <- RailTrail %>% 
    lm(volume ~ hightemp + cloudcover + weekday, data = RailTrail)
}

but I get the following error:

Error in xj[i]: invalid subscript type 'language'

Thank you,

Don't hesitate to ask further precision if my request is not clear.

Francisco

Do you mean the confidence interval for the model parameters? If so, this example I hope illustrates a succinct way of doing so:

model <- lm(mpg ~ cyl + disp + gear, data = mtcars)
bind_cols(broom::tidy(model), broom::confint_tidy(model))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM