--- title: "Jan25" output: html_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` Similating the central limit theorem: Normal data sample size 4 ```{r} n <- 4 data.norm <- matrix(rnorm(n*10000, mean=5, sd=2), nrow=10000) means.norm <- rowMeans(data.norm) hist(means.norm, breaks=100, col="green", prob=T) lines(seq(0,10,by=0.01), dnorm(seq(0,10, by=0.01), mean=5, sd=1), col="red", lwd=2) lines(seq(0,10,by=0.01), dnorm(seq(0,10, by=0.01), mean=5, sd=2)) ``` Sample Size 25 ```{r} # Increase n to 25 n <- 25 data.norm <- matrix(rnorm(n*10000, mean=5, sd=2), nrow=10000) means.norm <- rowMeans(data.norm) hist(means.norm, breaks=100, col="green", prob=T) lines(seq(0,10,by=0.01), dnorm(seq(0,10, by=0.01), mean=5, sd=0.4), col="red", lwd=2) ``` Non-normal data: exponential Sample size 4 ```{r} n <- 4 data.exp <- matrix(rexp(n*10000, 1),ncol=n) means.exp <- rowMeans(data.exp) hist(means.exp, breaks=100, col="green", prob=T) lines(seq(0,10,by=0.01), dnorm(seq(0,10, by=0.01), mean=1, sd=0.5), col="red", lwd=2) ``` Sample size 25 ```{r} n <- 25 data.exp <- matrix(rexp(n*10000, 1),ncol=n) means.exp <- rowMeans(data.exp) hist(means.exp, breaks=100, col="green", prob=T) lines(seq(0,10,by=0.01), dnorm(seq(0,10, by=0.01), mean=1, sd=0.2), col="red", lwd=2) ``` sample size 100 ```{r} n <- 100 data.exp <- matrix(rexp(n*10000, 1),ncol=n) means.exp <- rowMeans(data.exp) hist(means.exp, breaks=100, col="green", prob=T) lines(seq(0,10,by=0.01), dnorm(seq(0,10, by=0.01), mean=1, sd=0.1), col="red", lwd=2) ```