[Rd] ? bug in 'sample' (PR#8813)

doddl at mail.nih.gov doddl at mail.nih.gov
Thu Apr 27 17:35:53 CEST 2006


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]]



More information about the R-devel mailing list