I'm new to R and am trying to do some bootstrap estimates of standard errors for a large file of frequency data. I have the bootstrap working fine on a single data point, but I can't figure out how to save the output. Ideally, I would like to write only the standard error to a new file.
Here is what I've tried so far:
x = c(1,2,3,4,5,6,7,8,9,10)
samplemean = function(x, d){return(mean(x[d]))}
b = boot(x, samplemean, R=1000)
b
ORDINARY NONPARAMETRIC BOOTSTRAP
Call:
boot(data = x, statistic = samplemean, R = 1000)
Bootstrap Statistics :
original bias std. error
t1* 5.5 -0.0356 0.9145759
You can compute the standard errors using the t
(replication) slot in your boot
object.
require(boot)
x <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
samplemean <- function(x, d) {return(mean(x[d]))}
set.seed(123)
b <- boot(x,samplemean,R=1000)
b
## Bootstrap Statistics :
## original bias std. error
## t1* 5.5 -0.0232 0.90887
## str(b) first...
apply(b$t, 2, sd)
##[1] 0.90887