library(tidyverse)
## ── Attaching packages ───────────────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.1.0 ✔ purrr 0.3.1
## ✔ tibble 2.0.1 ✔ dplyr 0.8.0.1
## ✔ tidyr 0.8.3 ✔ stringr 1.4.0
## ✔ readr 1.3.1 ✔ forcats 0.4.0
## ── Conflicts ──────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(readr)
library(ggplot2)
## Parsed with column specification:
## cols(
## Years = col_double()
## )
pop_mean <- mean(years$Years)
pop_sd <- sd(years$Years)
paste0("The Mean of the population: ", pop_mean)
## [1] "The Mean of the population: 3.52666666666667"
paste0("The Standard Deviation of the population: ", pop_sd)
## [1] "The Standard Deviation of the population: 2.29588679966326"
set.seed(57)
n <- 30
sample_1 <- sample(years$Years, size = n, replace = TRUE)
hist(sample_1, breaks = 5, border="blue", col="green", xlab = "Years in College")
sample1_mean <- round(mean(sample_1), digits = 4)
sample1_std <- round(sd(sample_1), digits = 4)
paste0("The Mean of Sample1:", sample1_mean)
## [1] "The Mean of Sample1:3.2833"
paste0("The Standard Deviation of Sample1: ", sample1_std)
## [1] "The Standard Deviation of Sample1: 1.8274"
set.seed(57)
n <- 30
sample_2 <- sample(years$Years, size = n, replace = TRUE)
hist(sample_2, breaks = 5, border="blue", col="green", xlab = "Years in College")
sample1_mean <- round(mean(sample_2), digits = 4)
sample1_std <- round(sd(sample_2), digits = 4)
paste0("The Mean of Sample1:", sample1_mean)
## [1] "The Mean of Sample1:3.2833"
paste0("The Standard Deviation of Sample1: ", sample1_std)
## [1] "The Standard Deviation of Sample1: 1.8274"
sample_means = rep(NA, 1000)
for(i in 1:1000){
sample <- sample(years$Years, size = n, replace = TRUE)
sample_means[i] = mean(sample)
}
paste0("Meann of the Sample Means: ", mean(sample_means), " The Mean of the population: ", pop_mean)
## [1] "Meann of the Sample Means: 3.53048333333333 The Mean of the population: 3.52666666666667"
paste0("Standard Deviation of the Sample Means: ", sd(sample_means))
## [1] "Standard Deviation of the Sample Means: 0.421429158449136"
paste0("The Standard Deviation of the population: ", pop_sd)
## [1] "The Standard Deviation of the population: 2.29588679966326"
hist(sample_means, ylim=c(0,.7),main = "", xlab = "Sample Means", prob = T, col = "darkred")
lines(density(sample_means), col = "darkblue", lwd = 2)
xmax <- qexp(0.995, rate=0.2)
xvals <- seq(0, xmax, length=1000)
```