[R] Variance Computing- - HELP!!!!!!!!!!!!!!!!!!
Wiener, Matthew
matthew_wiener at merck.com
Tue Aug 19 20:22:22 CEST 2003
Hi.
There is no reason the variance of a normal should decrease as you take
larger samples. Indeed, in your call itself, you say that you want a sample
from a normal with a standard deviation of 3, and so a variance of 9. As
expected, both of your estimates of variance are close to 9.
What should decrease is the variance of the estimate of the mean, which is
the variance of the sample divided by the number of elements in your sample.
That will indeed decrease as n increases.
Also, a couple of R programming points raised by your example:
You can populate your entire matrix of random numbers with a single call,
with good time savings. (That probably doesn't matter much in this toy
example, but might if you do larger simulations for some problem.)
For example: matrix(rnorm(100000, 0, 3), nr = 100, nc = 1000) gets you your
matrix "small".
Similarly, your loop over the rows for taking variance can be replaced by
yy <- apply(small, 1, var)
Which may not be faster, but is certainly easier to read. And of course
you'd want to replace the call to var with a function that calculates
standard error.
Hope this helps,
Matt Wiener
-----Original Message-----
From: Padmanabhan, Sudharsha [mailto:sudAR_80 at neo.tamu.edu]
Sent: Tuesday, August 19, 2003 1:43 PM
To: r-help at stat.math.ethz.ch
Subject: [R] Variance Computing- - HELP!!!!!!!!!!!!!!!!!!
Hello,
I am running a few simulations for clinical trial anlysis. I want some help
regarding the following.
We know trhat as the sample size increases, the variance should decrease,
but
I am getting some unexpected results. SO I ran a code (shown below) to check
the validity of this.
large<-array(1,c(1000,1000))
small<-array(1,c(100,1000))
for(i in 1:1000){large[i,]<-rnorm(1000,0,3)}
for(i in 1:1000){small[i,]<-rnorm(100,0,3)}}
yy<-array(1,100)
for(i in 1:100){yy[i]<-var(small[i,])}
y1y<-array(1,1000)
for(i in 1:1000){y1y[i]<-var(large[i,])}
mean(yy);mean(y1y);
[1] 8.944
[1] 9.098
This shows that on an average,for 1000 such samples of 1000 Normal numbers,
the variance is higher than that of a 100 samples of 1000 random numbers.
Why is this so?
Can someone please help me out????
Thanks.
Regards
~S.
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
------------------------------------------------------------------------------
Notice: This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA), and/or
its affiliates (which may be known outside the United States as Merck Frosst,
Merck Sharp & Dohme or MSD) that may be confidential, proprietary copyrighted
and/or legally privileged, and is intended solely for the use of the
individual or entity named on this message. If you are not the intended
recipient, and have received this message in error, please immediately return
this by e-mail and then delete it.
More information about the R-help
mailing list