In: Statistics and Probability
Both X and S2 are unbiased for the Poisson λ. Which is better? Use the following steps to answer this question.
a) Generate 200000 random numbers from the Poisson(λ = 2)
distribution and arrange them in a matrix with 20 rows. Thus you
have 10000 samples of size 20.
b) Compute the 10000 sample means and sample variances and store
them in objects means and vars, respectively.
c) Compute the average of the 10000 sample means and the average
of the 10000 sample variances. Report the two averages. Do they
support the claim that they are unbiased for λ = 2?
d) Compute the sample variance of the 10000 sample means and the
sample variance of the 10000 sample variances. Report the two
variances. Which estimator of λ is preferable.
We generate random numbers using R
The R code is
set.seed(0) # For same result
X=rpois(200000,2) # For generating random numbers
D=matrix(X,nrow=20) #Storing values in matrix
means=rowMeans(D) # calculate row mean and store it
rowVar <- function(x, ...) {
rowSums((x - rowMeans(x, ...))^2, ...)/(dim(x)[2] )
} # creating function for calculating row variance
vars=rowVar(D)
mean(means) #average of sample means
mean(vars) # average of sample variances
Var=function(x){ var(x)*((length(x)-1)/length(x))}
Var(means) # Variance of sample mean
Var(vars) # Variance of sample variances
#Variance of sample mean is less than Variance of sample
variances
#Estimator Sample mean is best preferable for λ
The Output of code is
>set.seed(0) # For same result
>X=rpois(200000,2) # For generating random numbers
>D=matrix(X,nrow=20) #Storing values in matrix
>means=rowMeans(D) # calculate row mean and store it
>rowVar <- function(x, ...) {
>rowSums((x - rowMeans(x, ...))^2, ...)/(dim(x)[2] )
>} # creating function for calculating row variance
>vars=rowVar(D)
>mean(means) #average of sample means
[1] 2.001445
>mean(vars) # average of sample variances
[1] 2.002059
#Both estimator are approximately equal to 2 i.e. Both are unbiased for λ = 2
>Var=function(x){ var(x)*((length(x)-1)/length(x))}
>Var(means) # Variance of sample mean
[1] 0.0001334735
>Var(vars) # Variance of sample variances
[1] 0.001134832
>#Variance of sample mean is less than Variance of sample variances
>#Estimator Sample mean is best preferable for λ