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)

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to