[R] Bootstrapping

Bastian Offermann bastian.offermann at googlemail.com
Tue Dec 6 18:17:29 CET 2011


Hello,

I am having some trouble setting up a bootstrapping prodecure. I create 
artificial data and would like to use these to bootstrap a t-test 
statistic from these. Especially I do not really get how boot uses the 
indices variable or i variable. Can anybody help out? Thanks!!

b0 <- 1/2                         # intercept as given
b1 <- 1                           # slope as given
n <- 20                           # of rand. numbers
u <- rnorm(n, mean=0, sd=1)       # generate data
x <- rnorm(n, mean=0, sd=1)       #
y <- b0 + b1*x + u                # model
mu <- 1

data1 <- matrix(, n, 2)            # Data from original draw

tval <- function(data1, i) {
                   data1[i,1] <- y
                   data1[i,2] <- x
                   m <- lm(data1[,1]~data1[,2])
                   p <- coef(m)[2]
                   t <- (coef(m)[2]-mu)/sqrt(vcov(m)[2,2])   # t-test
                   t

                     }
bs <- boot(data = data1, statistic = tval, R = 500, sim = "ordinary")
bs
ba <- boot.array(bs)[1:5,1:10]
ci <- boot.ci(bs, conf=0.95, index=1, type="all")
ci.bca <- ci$bca[4:5]
plot(bs, index=1)



More information about the R-help mailing list