set.seed(3)
lambda <- 2
vartheta <- 1 / lambda
n <- 5
sim_num <- 12345
samples <- matrix(rexp(n * sim_num, rate = lambda), nrow = sim_num)
vartheta1_hat <- rowMeans(samples)
vartheta2_hat <- rowSums(samples) / (n + 1)
bias1 <- mean(vartheta1_hat) - vartheta
bias2 <- mean(vartheta2_hat) - vartheta
var1 <- var(vartheta1_hat)
var2 <- var(vartheta2_hat)
mse1 <- mean((vartheta1_hat - vartheta)^2)
mse2 <- mean((vartheta2_hat - vartheta)^2)
cat("Theoretical Results (n=5, λ=2):\n",
"ϑ̂₁: Bias = 0, Variance =", vartheta^2 / n, ", MSE =", vartheta^2 / n, "\n",
"ϑ̂₂: Bias =", -vartheta / (n + 1), ", Variance =", (n * vartheta^2) / (n + 1)^2, ", MSE =", vartheta^2 / (n + 1), "\n\n")
## Theoretical Results (n=5, λ=2):
## ϑ̂₁: Bias = 0, Variance = 0.05 , MSE = 0.05
## ϑ̂₂: Bias = -0.08333333 , Variance = 0.03472222 , MSE = 0.04166667
cat("Simulation Results:\n",
"ϑ̂₁: Bias =", bias1, ", Variance =", var1, ", MSE =", mse1, "\n",
"ϑ̂₂: Bias =", bias2, ", Variance =", var2, ", MSE =", mse2, "\n")
## Simulation Results:
## ϑ̂₁: Bias = -0.001185451 , Variance = 0.05075666 , MSE = 0.05075396
## ϑ̂₂: Bias = -0.08432121 , Variance = 0.03524768 , MSE = 0.04235489
#Advantages**: Unbiased. On average, it equals the true value \(\vartheta\).
#Disadvantages**: Larger variance, especially for small samples, leading to higher uncertainty.
#Advantages**: Smaller MSE, meaning it has lower overall error compared to \(\hat{\vartheta}_1\
#Disadvantages**: Introduces a negative bias, systematically underestimating \(\vartheta\).
Typically, solutions to an exercise contain the following components:
Some text explaining how you approach the task…
Theoretical calculations (if needed), including assumptions and rationales
# definitions of functions
# commented R commands
Figures (if applicable)
Some text explaining what has been achieved, interpretations, and answers to the questions in the description of the task.