Skip to content

Instantly share code, notes, and snippets.

@toyeiei
Last active July 15, 2019 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toyeiei/d43186b16bd59828a2e17b19fd0ffdf2 to your computer and use it in GitHub Desktop.
Save toyeiei/d43186b16bd59828a2e17b19fd0ffdf2 to your computer and use it in GitHub Desktop.
Central Limit Theorem
## look at dataframe diamonds
library(tidyverse)
glimpse(diamonds)
## assume this is all prices (population)
pop_prices <- diamonds$price
## sample n=30, repeats 1000 times
sam_prices <- replicate(
1000, mean(sample(pop_prices, size = 30))
)
## check if the mean of sample means is close to the population mean
summary(pop_prices)
summary(sam_prices)
## look at the histogram
hist(sam_prices, xlim = c(1000, 7000))
## let's change line 10, size=1000. Look at the histogram again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment