[R] bootstrap question

Roger D. Peng rpeng at stat.ucla.edu
Fri Jun 13 00:09:29 CEST 2003


You are using the boot function incorrectly.  This is taken from the 
help page:


statistic: A function which when applied to data returns a vector
           containing the statistic(s) of interest.  When
           `sim="parametric"', the first argument to `statistic' must be
           the data.  For each replicate a simulated dataset returned by
           `ran.gen' will be passed.  In all other cases `statistic'
           must take at least two arguments.  The first argument passed
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
           will always be the original data. The second will be a vector
           of indices, frequencies or weights which define the bootstrap
           sample.

The default is nonparametric bootstrap (sim = "ordinary"), so you need 
to specify a function with TWO arguments.  Try

x <- rnorm(100)
boot(x, function(x, i) mean(x[i]), R = 1000)$t

-roger

Erin Hodgess wrote:
> Dear r People
> 
> 
> I have a bootstrap question, please.
> 
> (this may possibly be a problem with my understanding of the bootstrap)
> 
> Suppose I have a sample of size 15, x[1], ...x[15].
> 
> This is a sample which is small compared to the population.
> 
> by the way, the x[i] are iid and have a common distribution F.
> 
> As I understand the bootstrap, that function will take a user specified
> number of repititions.  In each repitition, each element x[i] has an
> equal chance of selection.
> 
> Suppose I want to estimate the mean.
> 
> In each rep, a new sample is generated.  the mean is calculated in each rep.
> 
> 
> I would like to see those means.
> 
> If I use the boot command,
> 
> boot(x,mean,R=40)$t
> 
> I thought that I would obtain 40 different values.  However, those $t values
> are all the same.
> 
> what am I doing wrong, please?
> 
> thanks yet again!
> 
> sincerely,
> Erin Hodgess
> mailto: hodgess at uhddx01.dt.uh.edu
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 
>




More information about the R-help mailing list