Home About us Mathematical Epidemiology Rweb EPITools Statistics Notes Web Design Contact us Links |
> w <- rbinom(10000,size=50,prob=0.1)
> w1 <- (w - 50*0.1)^2
> mean(w1)
> 50*0.1*0.9
What we did was to take a large sample, calculate the squared
deviation from the expected value, and use the sample mean of a
large sample of these values to approximate the true expected
value of this quantity (the squared difference (or deviation) from
the expected value).
It is possible to show that the expected squared deviation from
the expected value for a binomial random variable is N*p*(1-p).
This quantity is called the variance; thus the variance of the
binomial is given by N*p*(1-p).
> xx <- rbinom(20,size=50,prob=0.1)
> mean((xx-50*0.1)^2)
> mean((xx-mean(xx))^2)
> sum((xx-mean(xx))^2)/(20-1)
> var(xx)
So if I wanted to try to estimate the squared deviation from the
expected value using the sample mean of the data in place of the
true expected value, I am going to be getting numbers that are too
small.