In: Statistics and Probability
The exponential distribution with rate λ has mean μ = 1/λ. Thus the method of moments estimator of λ is 1/X. Use the following steps to verify that X is unbiased, but 1/X is biased.
a) Generate 10000 samples of size n = 5 from the standard exponential distribution (i.e. λ = 1) using rexp(50000) and arranging the 50000 random numbers in a matrix with 5 rows.
b) Use the apply() function to compute the 10000 sample means and store them in the object means. The 10000 estimators of λ can be stored in the object lambdas by lambdas = 1/means
c) Compute the sample mean of the object means, and sample mean of the object lambdas. What can you say about the bias of X and of 1/X?
d) Repeat with a sample of size n = 10, using rexp(100000), and report your estimate of the bias of 1/X. Has the bias decreased?
rm(list=ls(all=TRUE)) > #a) Given information > n=5; > lambda=1 ; > #Random Number Generation > samples=rexp(50000,lambda) > x=matrix(samples,nrow=5,ncol=10000) > dim(x) [1] 5 10000 > ##b) > means=apply(x,2,mean) > lambdas=1/means > ##c) > smeans=mean(means) > cat("Sample mean of object means=",smeans) Sample mean of object means= 1.010265 > slambdas=mean(lambdas) > cat("Sample mean of object lambdas=",slambdas) Sample mean of object lambdas= 1.234539 > cat("Bias of X is=",abs(lambda-smeans)) Bias of X is= 0.01026538 > cat("Bias of 1/X is=",abs(lambda-slambdas)) Bias of 1/X is= 0.2345389 > cat("Bias of X which is insignificant less than bias of 1/X, so that X is good estimator than 1/X, And hence X is Undbiased Estimator and 1/X is biased") Bias of X which is insignificant less than bias of 1/X, so that X is good estimator than 1/X, And hence X is Undbiased Estimator and 1/X is biased > ##d ) Procedure for n=10 > n=10; > lambda=1 > #Random Number Generation > samples=rexp(100000,lambda) > x=matrix(samples,nrow=10,ncol=10000) > dim(x) [1] 10 10000 > means=apply(x,2,mean) > lambdas=1/means > smeans=mean(means) > cat("Sample mean of object means=",smeans) Sample mean of object means= 0.9975897 > slambdas=mean(lambdas) > cat("Sample mean of object lambdas=",slambdas) Sample mean of object lambdas= 1.114355 > cat("Bias of X is=",abs(lambda-smeans)) Bias of X is= 0.002410267 > cat("Bias of 1/X is=",abs(lambda-slambdas)) Bias of 1/X is= 0.1143547 > cat("When n=5 the bias of 1/X is greater than the bias of 1/X when n=10,So we conclude that as sample size(n) increases bias of estimator decreases.") When n=5 the bias of 1/X is greater than the bias of 1/X when n=10,So we conclude that as sample size(n) increases bias of estimator decreases.