Relies on:
Problems:
We want to compare two groups. One group is wearing fancy hats, the other a the control group. We are interested in their creativity scores.
library(tidyverse)library(kableExtra)set.seed(12)# Number of people per groupN <- 50 # Population mean of creativity for people wearing fancy hatsmu_fancyhats <- 103 # Population mean of creativity for people wearing no fancy hatsmu_nofancyhats <- 98 # Average population standard deviation of both groupssigma <- 15
# Generate datafancyhats = tibble(Creativity = rnorm(N, mu_fancyhats, sigma), Group = "Fancy Hat")nofancyhats = tibble(Creativity = rnorm(N, mu_nofancyhats, sigma), Group = "No Fancy Hat")FancyHat <- bind_rows(fancyhats, nofancyhats) %>% mutate(Group = fct_relevel(as.factor(Group), "No Fancy Hat"))
FancyHat
## # A tibble: 100 x 2## Creativity Group ## <dbl> <fct> ## 1 80.8 Fancy Hat## 2 127. Fancy Hat## 3 88.6 Fancy Hat## 4 89.2 Fancy Hat## 5 73.0 Fancy Hat## 6 98.9 Fancy Hat## 7 98.3 Fancy Hat## 8 93.6 Fancy Hat## 9 101. Fancy Hat## 10 109. Fancy Hat## # … with 90 more rows
fancyhat_ttest <- t.test(Creativity ~ Group, var.equal = FALSE, data = FancyHat)
fancyhat_ttest_tab <- broom::tidy(fancyhat_ttest)
fancyhat_ttest_tab %>% select(estimate, estimate1, estimate2, statistic, p.value, conf.low, conf.high) %>% round(3) %>% kbl() %>% kable_classic(full_width = FALSE, html_font = "Cambria")
estimate | estimate1 | estimate2 | statistic | p.value | conf.low | conf.high |
---|---|---|---|---|---|---|
-1.647 | 99.209 | 100.856 | -0.637 | 0.526 | -6.78 | 3.486 |
1) We estimated two means (and two standard deviations). More specifically, we obtained point estimates.
2) We estimated the difference in means (again, a point estimate).
3) We computed a test statistic..
4) We computed the probability of obtaining a value for the test statistic that is at least as extreme as the one obtained. This is called a p-value.
Relies on:
Problems:
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
o | Tile View: Overview of Slides |
Esc | Back to slideshow |
Relies on:
Problems:
We want to compare two groups. One group is wearing fancy hats, the other a the control group. We are interested in their creativity scores.
library(tidyverse)library(kableExtra)set.seed(12)# Number of people per groupN <- 50 # Population mean of creativity for people wearing fancy hatsmu_fancyhats <- 103 # Population mean of creativity for people wearing no fancy hatsmu_nofancyhats <- 98 # Average population standard deviation of both groupssigma <- 15
# Generate datafancyhats = tibble(Creativity = rnorm(N, mu_fancyhats, sigma), Group = "Fancy Hat")nofancyhats = tibble(Creativity = rnorm(N, mu_nofancyhats, sigma), Group = "No Fancy Hat")FancyHat <- bind_rows(fancyhats, nofancyhats) %>% mutate(Group = fct_relevel(as.factor(Group), "No Fancy Hat"))
FancyHat
## # A tibble: 100 x 2## Creativity Group ## <dbl> <fct> ## 1 80.8 Fancy Hat## 2 127. Fancy Hat## 3 88.6 Fancy Hat## 4 89.2 Fancy Hat## 5 73.0 Fancy Hat## 6 98.9 Fancy Hat## 7 98.3 Fancy Hat## 8 93.6 Fancy Hat## 9 101. Fancy Hat## 10 109. Fancy Hat## # … with 90 more rows
fancyhat_ttest <- t.test(Creativity ~ Group, var.equal = FALSE, data = FancyHat)
fancyhat_ttest_tab <- broom::tidy(fancyhat_ttest)
fancyhat_ttest_tab %>% select(estimate, estimate1, estimate2, statistic, p.value, conf.low, conf.high) %>% round(3) %>% kbl() %>% kable_classic(full_width = FALSE, html_font = "Cambria")
estimate | estimate1 | estimate2 | statistic | p.value | conf.low | conf.high |
---|---|---|---|---|---|---|
-1.647 | 99.209 | 100.856 | -0.637 | 0.526 | -6.78 | 3.486 |
1) We estimated two means (and two standard deviations). More specifically, we obtained point estimates.
2) We estimated the difference in means (again, a point estimate).
3) We computed a test statistic..
4) We computed the probability of obtaining a value for the test statistic that is at least as extreme as the one obtained. This is called a p-value.