knitr::opts_chunk$set(echo = TRUE)
library(SDS100)


# download the data
download_data("Gettysburg_sample_ave_word_lengths.rda")
download_data("gettysburg.Rda")

$\$

Gettysburg address word length distribution

Let's create a histogram of the lengths of the 268 words in the Gettysburg address.

# load the actual gettysburg address words and compute mu
load("gettysburg.Rda")

# get the actual number of letters in the Gettysburg address (population)
real_num_letters <- gettysburg$num_letters

# calculate the average of the population of word lengths (mu)




# Create a histogram of the word lengths




# plot the average word length as a red line

$\$

Student samples of average word lengths from 10 words

Let's create a histogram of the average word length $\bar{x}$ from n = 10 word that students sampled from the Gettysburg address.

# load the class average word lengths and compute the mean E[x-bar]
load("Gettysburg_sample_ave_word_lengths.rda")


# get a vector of the each students average word length x-bar
average_word_lengths <- word_lengths$Ave_word_lengths


# take the average of the x-bar's  E[x-bar]




# create a histogram of the class average word lengths





# add line for mu 




# add a line for E[x-bar]

$\$

Using R to get samples of average word lengths from 10 words

Let's use R to randomly (uniformly) sample 10 words from the Gettysburg address and calculate the average $\bar{X}$ of 10 randomly sampled words.

You can also explore this using this app: https://ethan-meyers-test.shinyapps.io/gettysburg_sampling_distribution/

library(SDS100)


# you can ignore this code for now
# we will explain how this works soon...
sampling_distribution <- do_it(10000) * {

  random_sample <- sample(real_num_letters, 10)
  mean(random_sample)

}


# get the mean of the sampling distribution 
mean_sampling_distributon <- mean(sampling_distribution)


# create a histogram of the randomly sampled average word lengths
hist(sampling_distribution,
     breaks = 30,
     xlab = "Average word length of 10 words",
     main = "Histogram of average of 10 words")



# add line at mu 


# add a line at E[x-bar]



# add a line at the mean of the sampling distribution 


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