[R] Random # generator accuracy
Jim Bouldin
jrbouldin at ucdavis.edu
Thu Jul 23 19:59:56 CEST 2009
Dan Nordlund wrote:
"It would be necessary to see the code for your 'brief test' before anyone
could meaningfully comment on your results. But your results for a single
test could have been a valid "random" result."
I've re-created what I did below. The problem appears to be with the
weighting process: the unweighted sample came out much closer to the actual
than the weighted sample (>1% error) did. Comments?
Jim
> x
[1] 1 2 3 4 5 6 7 8 9 10 11 12
> weights
[1] 1 1 1 1 1 1 2 2 2 2 2 2
> a = mean(replicate(1000000,(sample(x, 3, prob = weights))));a # (1
million samples from x, of size 3, weighted by "weights"; the mean should
be 7.50)
[1] 7.406977
> 7.406977/7.5
[1] 0.987597
> b = mean(replicate(1000000,(sample(x, 3))));b # (1 million samples from
x, of size 3, not weighted this time; the mean should be 6.50)
[1] 6.501477
> 6.501477/6.5
[1] 1.000227
Jim Bouldin, PhD
Research Ecologist
Department of Plant Sciences, UC Davis
Davis CA, 95616
530-554-1740
More information about the R-help
mailing list