2

I want to save and use later the bootstrapped regression coefficients of a regression model using the library 'boot' in R. In the example below, I want to be able to see and use the 1,000 bootstrapped coefficients for 'wt'. Is there a way to do so?

library(boot)

set.seed(6967)    # Make the results reproducible

bs <- function(formula, data, indices) {
    d <- data[indices, ]
    fit <- lm(formula, data=d)
    return(coef(fit))
}

results <- boot(data=mtcars, statistic=bs, R=1000, formula=mpg~wt+disp)

results

ORDINARY NONPARAMETRIC BOOTSTRAP


Call:
boot(data = mtcars, statistic = bs, R = 1000, formula = mpg ~ 
    wt + disp)


Bootstrap Statistics :
       original        bias    std. error
t1* 34.96055404 -0.0095950965 2.596330855
t2* -3.35082533 -0.0139963846 1.141259963
t3* -0.01772474 -0.0002011716 0.008307083
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
Spyros
  • 56
  • 7
  • 1
    Try `head(results$t)`. This will give you the first 6 rows of the complete results. You want column 2. – Rui Barradas Mar 23 '18 at 15:28
  • Thanks Rui, this worked. I used this code to end-up with a single variable: df <- data.frame(results$t) x <- df[,2, drop=FALSE] – Spyros Mar 23 '18 at 16:25

0 Answers0