File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
You can’t perform that action at this time.
0 commit comments