s-news
[Top] [All Lists]

Re: Bootstrapping with different sample sizes

To: Andrew.Davidson@CCRS.NRCan.gc.ca
Subject: Re: Bootstrapping with different sample sizes
From: Tim Hesterberg <timh@insightful.com>
Date: 27 Aug 2004 10:55:48 -0700
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <B7F9814D6850C949947CF8DEA134778101AD9F26@s5-ccr-r2.ccrs.nrcan.gc.ca> (Andrew.Davidson@CCRS.NRCan.gc.ca)
References: <B7F9814D6850C949947CF8DEA134778101AD9F26@s5-ccr-r2.ccrs.nrcan.gc.ca>
Andrew Davidson wrote:

>Apolgies if this question has been asked before - I could not find it
>answered in among the archives.
>
>I want to alter the bootstrap function (Splus 6; W2K) so that the number of
>samples randomly selected is n / 2 (not n, as is used in the original
>function).
>
>I have tried to fix this manually, but am a newbie to splus and am having no
>luck. Any advice on how to change the code would be much appreciated.

Rich Heiberger responded:
>Get the new bootstrap functions and then see if they give you the
>options you need.  This is Tim Hesterberg's signature file which
>describes them.
(see below for my signature)

Thanks, Rich.  I'll elaborate.


Download the S+Resample library, then you can do either of:
        bootstrap(x, mean, sampler = samp.bootstrap(size = length(x)/2))
        bootstrap(x, mean, sampler.args = list(size = length(x)/2))
(if x is a vector; use nrow(x) or numRows(x) more generally).


If you want to do this a lot, then you can define your own sampler, e.g.
        mySampler <- function(n, B, size = n/2){
          # draw samples of size n/2 by default
          samp.bootstrap(n, B, size = size)
        }
Then call e.g.
        bootstrap(x, mean, sampler = mySampler)

Or you can create "myBootstrap" which calls mySampler rather than
samp.bootstrap.

        myBootstrap <- bootstrap
        myBootstrap$sampler <- mySampler

You should not modify bootstrap() itself, or samp.bootstrap(), to
change the size.  Doing that causes discrepancies and makes it hard to
track down errors -- you'd get different results with a call to
bootstrap than someone else would.

The answers above presume that you want sampling with replacement.
For sampling without replacement use samp.permute instead of samp.bootstrap;
this also accepts a size argument.


========================================================
| Tim Hesterberg       Research Scientist              |
| timh@insightful.com  Insightful Corp.                |
| (206)802-2319        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

I'll teach "Bootstrap Methods and Permutation Tests"
at the 2004 Insightful User Conference in Boston, Oct 19; see
http://www.insightful.com/news_events/2004uc


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