[R] rnorm??
Adaikalavan Ramasamy
ramasamy at cancer.org.uk
Tue Feb 22 02:23:56 CET 2005
1) Why do you think there is a bug in rnorm. What is your expected
numbers for cases > 4 or cases < -4 ? If you can show your calculations
then maybe we can see if there is an error in how you calculated it or
with R.
2) Please give a reproducible example. It might be low or high in one
instance on a single run but if you do it several times you may not see
a consistent bias. If you do, then there could be a bug. Otherwise it
could be an element of randomness.
B <- 10 # increase this if you can
out1 <- matrix( nr=B, nc=2 )
out2 <- matrix( nr=B, nc=2 )
thr <- 4
set.seed(1)
for(i in 1:B){
x <- rnorm(1000000)
out1[ i, 1 ] <- mean( x > thr ) # empirical upper tail prob
out1[ i, 2 ] <- mean( x < -1*thr ) # empirical lower tail prob
y <- qnorm(runif(1000000))
out2[ i, 1 ] <- mean( y > thr )
out2[ i, 2 ] <- mean( y < -1*thr )
rm(x, y); print(i)
}
> out1
[,1] [,2]
[1,] 3.6e-05 3.7e-05
[2,] 3.2e-05 2.6e-05
[3,] 3.2e-05 2.9e-05
[4,] 3.7e-05 2.8e-05
[5,] 3.5e-05 2.5e-05
[6,] 4.3e-05 3.3e-05
[7,] 3.9e-05 3.0e-05
[8,] 3.2e-05 4.8e-05
[9,] 3.0e-05 3.1e-05
[10,] 3.4e-05 3.7e-05
> out2
[,1] [,2]
[1,] 3.5e-05 2.4e-05
[2,] 2.4e-05 3.5e-05
[3,] 4.1e-05 2.6e-05
[4,] 2.5e-05 3.9e-05
[5,] 4.1e-05 2.5e-05
[6,] 4.0e-05 3.1e-05
[7,] 2.9e-05 2.7e-05
[8,] 3.1e-05 3.3e-05
[9,] 3.5e-05 2.5e-05
[10,] 2.7e-05 3.4e-05
The probability of observing any value above 4 or below -4 is pnorm(4,
lower.tail=FALSE) = 3.167124e-05. There does not seem to be anything
suspicious from the run of 10.
3) I think this question might be more appropriate to post this question
to R-devel. Please use an informative subject line. Please read the
posting guide. Thanks.
Regards, Adai
On Mon, 2005-02-21 at 15:45 -0800, Scholz, Fritz wrote:
> I am wondering whether there is a bug in rnorm.
> When generating rnorm(1000000) and counting
> the cases > 4 and the cases < (-4) I get rather
> unexpectedly low counts for the latter. The problem goes away
> when using qnorm(runif(1000000)).
>
> Fritz Scholz, PhD
> Applied Statistics Group
> Boeing Phantom Works
> fritz.scholz at pss.boeing.com
> 425-865-3623
> Tu/We 206-542-6545 (most likely)
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list