Skip to content

Instantly share code, notes, and snippets.

@carlislerainey
Created September 9, 2025 15:26
Show Gist options
  • Select an option

  • Save carlislerainey/edb70a6f0da2d27f1116cc2b7606330d to your computer and use it in GitHub Desktop.

Select an option

Save carlislerainey/edb70a6f0da2d27f1116cc2b7606330d to your computer and use it in GitHub Desktop.
Code for parametric bootstrap for the toothpaste cap problem
pi_hat <- 8/150 # ml estimate from observed data
n_bs <- 2000
bs_est <- numeric(n_bs) # a container for the estimates
for (i in 1:n_bs) {
bs_y <- rbinom(150, size = 1, prob = 8/150)
bs_est[i] <- mean(bs_y)
}
print(sd(bs_est), digits = 2) # se estimate
print(quantile(bs_est, probs = c(0.05, 0.95)), digits = 2) # 90% ci
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment