[R] Variance Computing- - HELP!!!!!!!!!!!!!!!!!!

Jonathan Baron baron at psych.upenn.edu
Tue Aug 19 20:08:31 CEST 2003


On 08/19/03 17:42, Padmanabhan, Sudharsha wrote:
>
>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?

Don't know, but it could be a fluke.  You don't say how many
times you did it.

I did the following, with 1000 in each test.  You have 100 in the
small test and 1000 in the big one.  My numbers look pretty
close.

> bigmat <- matrix(rnorm(1000000),1000,1000) # 1000 rows of 1000 each
> smallmat <- matrix(rnorm(100000),1000,100) # 1000 rows of 100 each
> mean(apply(bigmat,1,var)) # get variance of each row, then take mean
[1] 0.9999344
> mean(apply(smallmat,1,var))
[1] 0.9967427

-- 
Jonathan Baron, Professor of Psychology, University of Pennsylvania
Home page:            http://www.sas.upenn.edu/~baron
R page:               http://finzi.psych.upenn.edu/




More information about the R-help mailing list