You are on page 1of 3

4. The R code used for this problem was the following.

It was decided to
sample from a standard normal distribution (since a choice of a mean and
standard deviation was required to conduct the simulation, and this was the
simplest and most logical option). The code would, however, be very
similar even if any other values for the mean and standard deviation were
chosen.
true_mean <- 0
B <- 1000 # simulation runs
n <- 10 # sample size
xbar <- 1:B # we will collect results in these two vectors
minmaxav <- 1:B
for (b in 1:B) { # repeat B times for b = 1,...,B
x <- rnorm(n)
xbar[b] <- mean(x) # compute and store X-bar
minmaxav[b] <- (min(x)+max(x))/2 # compute and store the average
of the minimum and maximum values
}
mean(xbar)
mean(minmaxav)
var(xbar)
var(minmaxav)
boxplot(xbar, minmaxav, names = c("X-bar", "minmaxav"),
col = "lightblue", horizontal = TRUE)
# Draw a dashed vertical line showing the true parameter value.
abline(v = true_mean, lty = 2, lwd = 2, col = "magenta")

After running the code up till the fourth-last line, we obtain the following
output:
> mean(xbar)
[1] -0.01348079
> mean(minmaxav)
[1] -0.0135379
> var(xbar)
[1] 0.09889252
> var(minmaxav)
[1] 0.1874148

It appears, thus, that both estimators are unbiased (since the true mean is
zero), but that Damjan’s estimator (minmaxav) has a larger variance than
Allan’s estimator (xbar).

The side-by-side boxplot below compares the sampling distributions of the


two estimators in diagrammatic form:

You might also like