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. USING R:
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 Xand 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?
Please answer with r code
R Code for (a), (b) and (c)
set.seed(999)
#a)
x = rexp(50000)
matrices = matrix(data = c(x), nrow = 5)
#b)
means = apply(matrices, 2, mean)
lambdas = 1/means
#c)
xbar = mean(means)
lambda.bar = mean(lambdas)
#bias for X-bar
xbar - 1 # 1/lambda = 1
#bias for 1/X-bar
lambda.bar - 1 # lambda = 1
On running the code, the bias of = 0.004988631 0
Thus, is unbiased.
The bias of = 0.2411502
Thus, is biased.
d)
set.seed(999)
#a)
x = rexp(100000)
matrices = matrix(data = c(x), nrow = 10)
#b)
means = apply(matrices, 2, mean)
lambdas = 1/means
#c)
xbar = mean(means)
lambda.bar = mean(lambdas)
#bias for X-bar
xbar - 1 # 1/lambda = 1
#bias for 1/X-bar
lambda.bar - 1 # lambda = 1
Running with n = 10, we get the bias of = 0.001238622 0
The bias of = 0.112071
Yes, the bias is decreased with increase in the sample size.