Reputation: 339
Does it have any methods to print all selected data when bootstrap is complete?
Once I use the following code
library(boot)
set.seed(1234)
rsq = function(data,indices) {
d = data[indices,]
fit = lm(formula=mpg~wt+disp,data=d)
return(summary(fit)$r.square)
}
results = boot(data = mtcars, statistic = rsq, R=1000)
print(results)
plot(results)
boot.ci(results,conf=0.95,type=c('perc','bca'))
BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 1000 bootstrap replicates
CALL :
boot.ci(boot.out = results, conf = 0.95, type = c("perc", "bca"))
Intervals :
Level Percentile BCa
95% ( 0.6838, 0.8833 ) ( 0.6344, 0.8549 )
to get confidence interval.I want to print all select obs which selected by bootstrap method.
Thanks.
Upvotes: 0
Views: 234
Reputation: 10411
You could do something like this:
ind <- list()
rsq <- function(data,indices) {
d <- data[indices,]
ind[[length(ind)+1]] <<- indices
fit <- lm(formula=mpg~wt+disp,data=d)
return(summary(fit)$r.square)
}
Then all your 1000 sets of indices would be in the list ind
.
Then maybe use unique to see which unique observations were sampled:
lapply(ind, unique)[1:2]
[[1]]
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
[[2]]
[1] 29 4 3 15 16 7 32 5 31 17 28 20 26 19 10 18 1 6 24 8
Upvotes: 1