Example of using bootstraps to estimate SE of a mean
Just a little game to know better bootstraps. Note that when the number of observations is low, the estimator is biased.
See here for a solution:
Bondy, Warren; Zlot, William (1976). "The Standard Error of the Mean and the Difference Between Means for Finite Populations". The American Statistician. 30 (2): 96–97.
finalerr <- NULL
reptest <- c(10000, 50000, 100000)
ltest <- c(10, 20, 30, 50, 100, 200, 300, 400, 500)
for (rep in reptest) {
perror <- NULL
for (l in ltest) {
taille <- runif(n=l, min=160, max=180)
# The standard error of the series
# sd(taille)/sqrt(l)
m <- rep(NA, rep)
for (i in 1:rep) m[i] <- mean(taille[sample(x=1:l, size = l, replace = TRUE)])
# The standard deviation of the means obtained using bootstrap
# sd(m)
perror <- c(perror, 100*(sd(m)-(sd(taille)/sqrt(l)))/(sd(taille)/sqrt(l)))
}
finalerr <- cbind(finalerr, perror)
}
plot(ltest, finalerr[, 1], las=1, bty="n", type="n", ylim=c(-5, 2), xlab="Number of observations",
ylab="Percent of error for SE")
segments(x0=0, x1=500, y0=0, y1=0, lty=2)
lines(x=ltest, y=finalerr[, 1], col="black")
lines(x=ltest, y=finalerr[, 2], col="blue")
lines(x=ltest, y=finalerr[, 3], col="red")
legend("bottomright", legend=c("10000", "50000", "100000"),
lty=1, col=c("black", "blue", "red"), title = "Number of boostraps")
See here for a solution:
Bondy, Warren; Zlot, William (1976). "The Standard Error of the Mean and the Difference Between Means for Finite Populations". The American Statistician. 30 (2): 96–97.
finalerr <- NULL
reptest <- c(10000, 50000, 100000)
ltest <- c(10, 20, 30, 50, 100, 200, 300, 400, 500)
for (rep in reptest) {
perror <- NULL
for (l in ltest) {
taille <- runif(n=l, min=160, max=180)
# The standard error of the series
# sd(taille)/sqrt(l)
m <- rep(NA, rep)
for (i in 1:rep) m[i] <- mean(taille[sample(x=1:l, size = l, replace = TRUE)])
# The standard deviation of the means obtained using bootstrap
# sd(m)
perror <- c(perror, 100*(sd(m)-(sd(taille)/sqrt(l)))/(sd(taille)/sqrt(l)))
}
finalerr <- cbind(finalerr, perror)
}
plot(ltest, finalerr[, 1], las=1, bty="n", type="n", ylim=c(-5, 2), xlab="Number of observations",
ylab="Percent of error for SE")
segments(x0=0, x1=500, y0=0, y1=0, lty=2)
lines(x=ltest, y=finalerr[, 1], col="black")
lines(x=ltest, y=finalerr[, 2], col="blue")
lines(x=ltest, y=finalerr[, 3], col="red")
legend("bottomright", legend=c("10000", "50000", "100000"),
lty=1, col=c("black", "blue", "red"), title = "Number of boostraps")
Commentaires
Enregistrer un commentaire