Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbiostat authored Dec 7, 2022
1 parent 137a63b commit 32d1ed9
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions code/lognormal_median_bootstrap.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
N <- 100
Mu <- -0.5
Sigma <- 2
true.Median <- exp(Mu)
#####
X <- rlnorm(n = N, meanlog = Mu, sdlog = Sigma)

### Assignment: assess the normal approximation

###

hist(X, probability = TRUE)
m.hat <- median(X)

Nboot <- 200
npboot.ests <- rep(NA, Nboot)

for(i in 1:Nboot){
Xrep <- sample(X, size = N, replace = TRUE)
npboot.ests[i] <- median(Xrep)
}

hist(npboot.ests, probability = TRUE, col ='lightblue2',
main = "Bootstrap estimates of the median")
abline(v = m.hat, lwd = 3, lty = 2, col = "red")
abline(v = true.Median, lwd = 3, lty = 3)
legend(x = "topright",
legend = c("Point estimate", "True Median"),
col = c("red", "black"), lwd = 3,
lty = c(2, 3), bty = 'n')





0 comments on commit 32d1ed9

Please sign in to comment.