Skip to content
Prev 106759 / 398506 Next

Error: cannot take a sample larger than the population

Aldi,

Your concept of sample is different from mine. 
I would expect with replacement to be equivalent for a for loop of sampling 
without replacement.
samples <- 1:400
for (i in 1:400) samples[i] <- sample(c(0,1,2),1 ,prob=c(0.02 ,0.93 ,0.05 ))
Sampling without replacement:
first :  sample(c(0,1,2),1 ,prob=c(0.02 ,0.93 ,0.05 ))
second: depending on first (suppose 2 was selected)
	 sample(c(0,1),1 ,prob=c(0.02 ,0.93)/.95)
third: whatever is remaining with probability 1.

n.b. the second is equivalent to  sample(c(0,1),1 ,prob=c(0.02 ,0.93)), since 
sample normalized the probabilities itself.

Concerning your result:
observed <- c(0.0200, 0.9225, 0.0575 )*400
expected  <- c(0.02 ,0.93 ,0.05 )*400
stat <- sum((observed-expected)^2/expected)
pchisq(stat,2,lower=FALSE)
[1] 0.788915

Seems ok to me.

Cheers,
Kees
On Saturday 30 December 2006 16:55, Aldi Kraja wrote: