n <- 100 # sample size
nsim <- 100 # number of simulations
mu <- 0
T <- Tunb <- rep(NA, nsim)
theta <- mu^2 # E(X)^2, with X following N(mu, 1)
for (i in 1:nsim){
x <- rnorm(n, mean = mu, sd = 1)
T[i] <- squaredIntEstim(x, method = "biased")
Tunb[i] <- squaredIntEstim(x, method = "unbiased")
}
par(mfrow = c(1, 1))
boxplot(cbind(T, Tunb))
abline(h = theta, col = "red")
abline(h = c(mean(T), mean(Tunb)), col = c("blue", "cyan"), lty = "dotted")
# look at the difference between median and mean
Run the code above in your browser using DataLab