Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 47
Kernel: R (R-Project)

Lecture 13: Boostrap and Confidence Intervals

  • Mean, Median, Mode, Percentiles

  • The Bootstrap Method; Confidence Intervals

mylist4 <- c( 75, 57, 75, 81, 89, 100) sort(mylist4)
  1. 57
  2. 75
  3. 75
  4. 81
  5. 89
  6. 100
quantile( mylist4, 0.6, type = 1 )
60%: 81
library('dplyr') library('ggplot2')
Attaching package: ‘dplyr’ The following objects are masked from ‘package:stats’: filter, lag The following objects are masked from ‘package:base’: intersect, setdiff, setequal, union
payroll <- read.csv( 'citywidepayroll_small.csv' )
original_sample <- sample( payroll$Regular.Gross.Paid, 100, replace = FALSE )
bootstrap_samples <- data.frame( ave_RGP = double(2000) ) count <- 1 while( count <= 2000){ sample_group <- sample( original_sample, 100, replace = TRUE ) bootstrap_samples$ave_RGP[count] <- mean( sample_group ) count <- count + 1 }
ggplot( bootstrap_samples, aes( x = ave_RGP )) + geom_histogram( bins = 20 )
Image in a Jupyter notebook
mean( bootstrap_samples$ave_RGP)
49001.02280295
true_ave <- mean( payroll$Regular.Gross.Paid) true_ave
39952.342948