What in the world am I missing??> x<-rnorm(20)> mean(x)[1] -0.2272851> results<-boot(x,mean,R=5)> results[2]$t [,1] [1,] -0.2294562 [2,] -0.2294562 [3,] -0.2294562 [4,] -0.2294562 [5,] -0.2294562 Jeff Morris Ortho-Clinical Diagnostics A Johnson & Johnson Co. Rochester, NY Tel: (585) 453-5794 [[alternative HTML version deleted]]
On Thu, 1 Apr 2004 17:19:55 -0500 Morris, Jeffrey [OCDUS] wrote:> What in the world am I missing??The help page? As help(boot) tells you: statistic: <snip> 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, <snip> So I would think you want to do: R> mymean <- function(x, index) mean(x[index]) R> boot(x, mymean, R = 20) ORDINARY NONPARAMETRIC BOOTSTRAP Call: boot(data = x, statistic = mymean, R = 20) Bootstrap Statistics : original bias std. error t1* 0.1775 0.03224225 0.1302358 hth, Z> > x<-rnorm(20) > > > mean(x) > [1] -0.2272851 > > > results<-boot(x,mean,R=5) > > > results[2] > $t > [,1] > [1,] -0.2294562 > [2,] -0.2294562 > [3,] -0.2294562 > [4,] -0.2294562 > [5,] -0.2294562 > > Jeff Morris > Ortho-Clinical Diagnostics > A Johnson & Johnson Co. > Rochester, NY > Tel: (585) 453-5794 > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
What you are missing is reading the helpfile! The function mean is not a valid statistic to be passed to boot function(x, i) mean(x[i]) is. Please do read the documentation. That's why it is provided. ------------------------------------------------------------------ | Angelo J. Canty Email: cantya at mcmaster.ca | | Mathematics and Statistics Phone: (905) 525-9140 x 27079 | | McMaster University Fax : (905) 522-0935 | | 1280 Main St. W. | | Hamilton ON L8S 4K1 | ------------------------------------------------------------------ On Thu, 1 Apr 2004, Morris, Jeffrey [OCDUS] wrote:> What in the world am I missing?? > > > x<-rnorm(20) > > > mean(x) > [1] -0.2272851 > > > results<-boot(x,mean,R=5) > > > results[2] > $t > [,1] > [1,] -0.2294562 > [2,] -0.2294562 > [3,] -0.2294562 > [4,] -0.2294562 > [5,] -0.2294562 > > Jeff Morris > Ortho-Clinical Diagnostics > A Johnson & Johnson Co. > Rochester, NY > Tel: (585) 453-5794 > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
> What in the world am I missing??stype. As in (from help(boot) stype: A character string indicating what the second argument of statistic represents. Possible values of stype are '"i"' (indices - the default), '"f"' (frequencies), or '"w"' (weights). This works. n.b. the second argument. mean.b <- function(x,ind,...) { mean(x[ind]) } zz <- rnorm(20) mean(zz) res <- boot(zz,mean.b,R=5) I'm sure there's a cleaner way to do that, but I don't know it (yet). Cheers Jason
You have to let boot pass the index for selection to the function as well. So, for example, try: boot.mean <- function(data, index) mean(data[index]) results <- boot(x, boot.mean, R=5) Andrew. On Thursday 01 April 2004 14:19, Morris, Jeffrey [OCDUS] wrote:> What in the world am I missing?? > > > x<-rnorm(20) > > > > mean(x) > > [1] -0.2272851 > > > results<-boot(x,mean,R=5) > > > > results[2] > > $t > [,1] > [1,] -0.2294562 > [2,] -0.2294562 > [3,] -0.2294562 > [4,] -0.2294562 > [5,] -0.2294562 > > Jeff Morris > Ortho-Clinical Diagnostics > A Johnson & Johnson Co. > Rochester, NY > Tel: (585) 453-5794 > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html-- Andrew Robinson Ph: 208 885 7115 Department of Forest Resources Fa: 208 885 6226 University of Idaho E : andrewr at uidaho.edu PO Box 441133 W : http://www.uidaho.edu/~andrewr Moscow ID 83843 Or: http://www.biometrics.uidaho.edu No statement above necessarily represents my employer's opinion.
> > x<-rnorm(20) > > mean(x) > [1] -0.2272851 > > results<-boot(x,mean,R=5) > > What in the world am I missing??See http://www.mayin.org/ajayshah/KB/R/statistics.html -- Ajay Shah Consultant ajayshah at mayin.org Department of Economic Affairs http://www.mayin.org/ajayshah Ministry of Finance, New Delhi