5

I am a new R user, and am having trouble using the boot package. All I want to do is use bootstrapping to produce confidence intervals around a mean for a vector of numbers, such as:

x <- rnorm(100, 1, .5)

Any tips?

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
mike
  • 22,931
  • 31
  • 77
  • 100

1 Answers1

12

Doesn't the following suffice?

library(boot)
x <- rnorm(100, 1, .5)
b <- boot(x, function(u,i) mean(u[i]), R = 999)
boot.ci(b, type = c("norm", "basic", "perc"))
Vincent Zoonekynd
  • 31,893
  • 5
  • 69
  • 78
  • What do the 'u' and 'i' indicate here? – cryptic0 Oct 23 '13 at 14:19
  • 2
    @cryptic0: that is explained in `?boot`. `u` will be the original data (`x`, in this example), and `i` the vector of indices corresponding to a boostrap sample (the function will be called `R` times, for different samples). If the data is a vector, the bootstrap sample is `u[i]`, if it is a data.frame, it is `u[i,]`. (Of course, since `u` and `i` are the formal arguments of the function, they do not have any value outside this function.) – Vincent Zoonekynd Oct 23 '13 at 14:55