Skip to content

Commit 977075d

Browse files
committed
Study bootstrap method
1 parent fbd883e commit 977075d

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

R/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,3 +754,63 @@ int main() {
754754
std::cout << "Estimate: " << estimate << "\n";
755755
}
756756
```
757+
758+
## Bootstrap Method
759+
760+
Bootstrap is a resampling technique that can be used to make statistical inferences.
761+
762+
For given a specific sample x, one can use `sample(x, replace=TRUE)` to generate a resampling called `x∗` (a bootstrap sample).
763+
764+
- Assume unknown population distribution `F`
765+
- Assume unknown parameter `theta`
766+
- estimator `theta_hat = T(X)`
767+
768+
Setup:
769+
```r
770+
set.seed(251407053)
771+
772+
n <- 50
773+
true_mu <- 10
774+
775+
x <- rnorm(n, mean = true_mu, sd = 2) # To be replaced with real dataset
776+
777+
theta_hat <- mean(x) # estimator T(X)
778+
theta_hat
779+
```
780+
781+
Bootstrap resampling:
782+
783+
```r
784+
B <- 10000 # number of bootstrap samples
785+
786+
bootstrap_stats <- replicate(B, {
787+
788+
x_star <- sample(x, size = n, replace = TRUE)
789+
790+
mean(x_star) # T(X*)
791+
})
792+
```
793+
794+
Bootstrap variance estimate:
795+
796+
```r
797+
boot_var <- var(bootstrap_stats)
798+
boot_var
799+
```
800+
801+
Bootstrap bias estimate:
802+
803+
```r
804+
boot_bias <- mean(bootstrap_stats) - theta_hat
805+
boot_bias
806+
```
807+
808+
Bootstrap confidence interval:
809+
810+
```r
811+
alpha <- 0.05
812+
813+
ci <- quantile(bootstrap_stats, probs = c(alpha/2, 1 - alpha/2))
814+
ci
815+
```
816+

0 commit comments

Comments
 (0)