knitr::opts_chunk$set(echo = TRUE)

Simple example of sampling with replacement

library(SDS100)


# simple vector
my_sample <- c(3, 1, 4, 1, 5, 9)


# resampling values in the vector with replacement

$\$

Simple fake data bootstrap example

# simple bootstrap example

my_sample <- c(21, 29, 25, 19, 24, 22, 25, 26, 25, 29)


# calculate the x-bar statistic



# create the bootstrap distribution






# visualize the bootstrap distribution




# calculate the standard error




# 95% confidence interval

$\$

Let's try the Gettysburg address example

# Get the Gettysburg population data
# SDS100::download_data("gettysburg.Rda")   

load("gettysburg.Rda")

word_lengths <- gettysburg$num_letters 





# We can use the sample(data_vec, n) to get a sample of length n:




# calculate the actual x-bar




# Let's create a sampling distribution in R







# visualize the bootstrap distribution



# get the bootstrap standard error SE*




# 95% confidence interval







# Is the actual parameter value mu in the confidence interval?  


emeyers/SDS100 documentation built on April 28, 2024, 5:07 p.m.