From doddl at mail.nih.gov  Thu Apr 27 17:35:53 2006
From: doddl at mail.nih.gov (doddl at mail.nih.gov)
Date: Thu, 27 Apr 2006 17:35:53 +0200 (CEST)
Subject: [Rd] ? bug in 'sample' (PR#8813)
Message-ID: <20060427153553.2742347718@slim.kubism.ku.dk>

I have found that specifying different "sizes" in the sample command has
a funny effect on the random sampling.  The code below is a condensed
version of a function I wrote to simulate a bootstrap method.  For
simplicity, I eliminated the internal bootstrap loop, but kept a
statement to draw one bootstrap sample, because this is where the
problem occurs.  The output (mean(y)^2) should be the same for the two
runs of the function below, since it is based on the original rnorm
draw.  For the first iteration of this function, it is, but thereafter
the results aren't the same.  If I run this code in Splus, the results
are the same.  Also, if I set the size argument to be the same (or
eliminate this line altogether), I get reproducible results.=20=20

=20

I'm using R 2.2.0

=20

Thanks,

-Lori

=20

test.fun<-function(nsamp, mu,q, seed, nsim=3D2){

set.seed(seed)=20=20=20=20

mnsq<-rep(NA,nsim)

for (i in 1:nsim){

y<-rnorm(nsamp,mean=3Dmu)

yboot<-sample(y, size=3Dq, replace=3DT)

mnsq[i]<-(mean(y)^2)

}

return(mnsq)

}

=20

test.fun(50,0,30,12345)

test.fun(50,0,10,12345)

=20

Lori E. Dodd, Ph.D.

National Cancer Institute

Biometric Research Branch

6130 Executive Blvd, MSC 7434

Rockville, MD 20892=20

(For overnight deliveries use 20852)

=20

Phone: 301-402-0383

FAX:    301-402-0560

Email: doddl at mail.nih.gov

=20


	[[alternative HTML version deleted]]



[Rd] ? bug in 'sample' (PR#8813)
doddl at mail.nih.gov