Skip to content

Commit 32d1ed9

Browse files
authored
Add files via upload
1 parent 137a63b commit 32d1ed9

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

code/lognormal_median_bootstrap.r

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
N <- 100
2+
Mu <- -0.5
3+
Sigma <- 2
4+
true.Median <- exp(Mu)
5+
#####
6+
X <- rlnorm(n = N, meanlog = Mu, sdlog = Sigma)
7+
8+
### Assignment: assess the normal approximation
9+
10+
###
11+
12+
hist(X, probability = TRUE)
13+
m.hat <- median(X)
14+
15+
Nboot <- 200
16+
npboot.ests <- rep(NA, Nboot)
17+
18+
for(i in 1:Nboot){
19+
Xrep <- sample(X, size = N, replace = TRUE)
20+
npboot.ests[i] <- median(Xrep)
21+
}
22+
23+
hist(npboot.ests, probability = TRUE, col ='lightblue2',
24+
main = "Bootstrap estimates of the median")
25+
abline(v = m.hat, lwd = 3, lty = 2, col = "red")
26+
abline(v = true.Median, lwd = 3, lty = 3)
27+
legend(x = "topright",
28+
legend = c("Point estimate", "True Median"),
29+
col = c("red", "black"), lwd = 3,
30+
lty = c(2, 3), bty = 'n')
31+
32+
33+
34+
35+

0 commit comments

Comments
 (0)