13 Properties of Estimators and Tests
13.1 Comparing estimators
A normal distribution is symmetric about its mean, so that its mean and median coincide. The question therefore arises: Should we use the sample mean or the sample median to estimate that parameter? Both seem equally natural, but the mean corresponds to the maximum likelihood estimator (MLE). We can run some simulations to compare these estimators. And indeed, the sample mean is somewhat better than the sample median, at least in terms of mean squared error, which is the performance measure that we use here.
= 10
q = 2^(1:q) # sample sizes
n_grid = 1e3 # replicates
B = numeric(q)
mean_error = numeric(q)
median_error for (k in 1:q) {
= n_grid[k]
n = numeric(B)
mean_out = numeric(B)
median_out for (b in 1:B) {
= rnorm(n) # normal sample
x = mean(x) # sample mean
mean_out[b] = median(x) # sample median
median_out[b]
}= mean(mean_out^2) # MSE for the sample mean
mean_error[k] = mean(median_out^2) # MSE for the sample median
median_error[k]
}matplot(n_grid, cbind(mean_error, median_error), log = "xy", type = "b", lty = 1, pch = 15, lwd = 2, col = 2:3, xlab = "sample size", ylab = "mean squared error")
legend("topright", legend = c("sample mean", "sample median"), lty = 1, pch = 15, lwd = 2, col = 2:3)
If instead of considering a normal distribution we consider a double-exponential distribution, the situation is exactly reversed.
= 10
q = 2^(1:q) # sample sizes
n_grid = 1e3 # replicates
B = numeric(q)
mean_error = numeric(q)
median_error for (k in 1:q) {
= n_grid[k]
n = numeric(B)
mean_out = numeric(B)
median_out for (b in 1:B) {
= rexp(n)*sample(c(-1,1), n, TRUE) # sample
x = mean(x) # double-exponential sample mean
mean_out[b] = median(x) # sample median
median_out[b]
}= mean(mean_out^2) # MSE for the sample mean
mean_error[k] = mean(median_out^2) # MSE for the sample median
median_error[k]
}matplot(n_grid, cbind(mean_error, median_error), log = "xy", type = "b", lty = 1, pch = 15, lwd = 2, col = 2:3, xlab = "sample size", ylab = "(estimated) mean squared error")
legend("topright", legend = c("sample mean", "sample median"), lty = 1, pch = 15, lwd = 2, col = 2:3)
13.2 Uniformly most powerful tests
Consider testing \(Q_0\) versus \(Q_1\), two distributions on the same discrete space. The Neyman–Pearson Lemma implies that a likelihood ratio test (LRT) is most powerful at the level equal to its size. In turn, computing an LRT in the present setting involves solving an integer program. Below, we generate two random distributions on \(\{1, \dots, 10\}\), and then solve the integer program defining the LRT at level \(\alpha = 0.20\).
= runif(10)
Q0 = Q0/sum(Q0)
Q0 = runif(10)
Q1 = Q1/sum(Q1)
Q1 = Q1/Q0
LR
require(lpSolve)
= 0.20
alpha = Q1
Objective = t(as.matrix(Q0))
Constraint = lp("max", Objective, Constraint, "<=", alpha, all.bin = TRUE)
L = which(L$solution == 1) reject
The rejection region is
cat(reject)
2 4 5
The size of the test is the probability of rejecting under the null, that is, the probability of the rejection region under \(Q_0\)
sum(Q0[reject])
[1] 0.1519911
It is upper-bounded by the level by design.