s-news
[Top] [All Lists]

Re: Bootstrap rowMeans

To: "Kim Elmore" <Kim.Elmore@noaa.gov>
Subject: Re: Bootstrap rowMeans
From: Tim Hesterberg <timh@insightful.com>
Date: 14 Jan 2005 08:51:40 -0800
Cc: S-News <s-news@wubios.wustl.edu>
In-reply-to: <6.2.0.14.2.20050114101703.039d8fe0@129.15.69.4> (Kim.Elmore@noaa.gov)
References: <6.2.0.14.2.20050114101703.039d8fe0@129.15.69.4>
>I want to bootstrap the rowMeans of a matrix, and then perform a BCa 
>confidence interval on the resulting means. The help() for bootstrap() says 
>that it will accept a matrix as data and any statistic or expression that 
>returns a matrix or vector.
>
>So, I whipped out this simple example to make sure all is well:
>
>.testmat <- rbind(rnorm(10, 2), rnorm(10, 4), rnorm(10, 6))
>test.boot <- bootstrap(.testmat, rowMeans, trace=F)
>test.boot
>Call:
>bootstrap(data = .testmat, statistic = rowMeans)
>
>Number of Replications: 1000
>
>Summary Statistics:
>           Observed    Bias  Mean    SE
>rowMeans1    2.094  2.2363 4.330 1.897
>rowMeans2    4.097  0.0914 4.189 1.892
>rowMeans3    6.696 -2.3454 4.351 1.886
>
>The bootstrap estimates of the mean should be pretty close to the observed 
>mean, but they aren't. Given this, limits.bca() will yield nonsense. What's 
>wrong with how I've used bootstrap()?
>
>Kim Elmore

The bootstrap() function resamples rows, assuming that rows represent
observations randomly drawn from some multivariate distribution.

If instead your observations are in columns (which seems to be
the case, given that you are calculating rowMeans), then to
use bootstrap() you should transpose your data:

bootstrap(data = t(.testmat), statistic = colMeans)



Incidentally, the resample library will do this faster
than the version of bootstrap built into S-PLUS.

> x _ rmvnorm(300, d=10)
> sys.time( boot _ bootstrap(x, colMeans) )
# 2.2 seconds
> library(resample, first=T)
> sys.time( boot _ bootstrap(x, colMeans) )
# 0.42 seconds

Tim Hesterberg

========================================================
| Tim Hesterberg       Research Scientist              |
| timh@insightful.com  Insightful Corp.                |
| (206)283-8691        1700 Westlake Ave. N, Suite 500 |
| (206)802-2500 (fax)  Seattle, WA 98109-3044, U.S.A.  |
|                      www.insightful.com/Hesterberg   |
========================================================
Download the S+Resample library from www.insightful.com/downloads/libraries


<Prev in Thread] Current Thread [Next in Thread>