s-news
[Top] [All Lists]

Re: sample command as FUN element using tapply

To: Jourdan Gold <jgold@uoguelph.ca>
Subject: Re: sample command as FUN element using tapply
From: Tim Hesterberg <TimHesterberg@gmail.com>
Date: Wed, 03 Dec 2008 08:10:30 -0800
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <318983062.9039291228223558771.JavaMail.root@huron.cs.uoguelph.ca> (message from Jourdan Gold on Tue, 2 Dec 2008 08:12:38 -0500 (EST))
References: <318983062.9039291228223558771.JavaMail.root@huron.cs.uoguelph.ca>
Reply-to: TimHesterberg@gmail.com (Tim Hesterberg)
S+Resample supports sampling with size (stratum size - 1),
by setting 'reduceSize = 1' in many of the sampling functions,
including the finite population sampler.  Load the package
using
        library(resample)
in the latest version of S+.

here is an excerpt from the help file for the samplers:

samp.bootstrap(     n, B, size = n - reduceSize, reduceSize = 0, prob = NULL)
samp.boot.bal(      n, B, size = n - reduceSize, reduceSize = 0, method = 
"biased")
samp.bootknife(     n, B, size = n - reduceSize, reduceSize = 0, njack = 1)
samp.finite(        n, B, size = n - reduceSize, reduceSize = 0, N, bootknife = 
F)
samp.permute(       n, B, size = n - reduceSize, reduceSize = 0, prob = NULL, 
full.partition = "none")
samp.permute.old(   n, B)
samp.combinations(  n, B, k, both = T)
samp.combinations(  n, B)
samp.half(          n, B, size = n/2 - reduceSize, reduceSize = 0)
samp.blockBootstrap(n, B, size = n - reduceSize, reduceSize = 0, blockLength)

Tim Hesterberg


>my specific question is:
>
>I am attempting to create a bootstrap procedure for a finite sample using the 
>theory of Rao and Wu, JASA (1988) that replicates within each strata (h) n_h - 
>1 times. I am able to sample n_h times using an innitial call to the resample 
>function  I suspect that it has to do with providing extra info to the FUN 
>function but this seems to only allow one value i.e tapply(test, class, mean, 
>trim = 0.1). please note that I have cross-posted this email and apologise to 
>anyone who recieves it twice.
>
>i want to be able to have a different value of n for each 
>
>sampler <- function(x) 
>
>
>{  sample(x, replace = T)
>        
>        
>        
>}
>
>
>raoboot <- function (datavar, statavar, weight,  nboot)
>{
>        i <- 1
>sdatavar <- sort(datavar)
>sstratavar <- sort(statavar)
>sweight <- sort(weight)
> sdatavarwght <- sdatavar*sweight
> stramn <- tapply(sdatavar, sstratavar, mean)
> meanvect <- rep(0, times = nboot)
> while (i < nboot) 
>        { #vector of resampled observations
>                vectobsrestemp <- tapply(sdatavarwght, sstratavar, resampler)
>                vectobsres <- unlist(vectobsrestemp)
>        meanvect[i]        <- mean(vectobsres)
>i <- i + 1
>}
>                
>        repvectboot <- rep(mean(meanvect), times = i)
>        vb <- sum((repvectboot - meanvect)^2)/(i -1)
>}

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