Skip to content

Commit

Permalink
Table references ch6 (#167)
Browse files Browse the repository at this point in the history
* Removing bolding from the exercise solutions

* Referencing tables in text in ch6.
rpowell22 authored Aug 22, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 4c45bb6 commit 2ba717b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions 06-statistical-testing.Rmd
Original file line number Diff line number Diff line change
@@ -291,7 +291,7 @@ tidy(ttest_ex2)


\index{gt package|(} \index{p-value|(}
The 'tidied' output can also be piped into the {gt} package to create a table ready for publication. We go over the {gt} package in Chapter \@ref(c08-communicating-results). The function `pretty_p_value()` comes from the {prettyunits} package and converts numeric p-values to characters and, by default, prints four decimal places and displays any p-value less than 0.0001 as `"<0.0001"`, though another minimum display p-value can be specified [@R-prettyunits].
The 'tidied' output can also be piped into the {gt} package to create a table ready for publication (see Table \@ref(tab:stattest-ttest-ex2-gt-tab)). We go over the {gt} package in Chapter \@ref(c08-communicating-results). The function `pretty_p_value()` comes from the {prettyunits} package and converts numeric p-values to characters and, by default, prints four decimal places and displays any p-value less than 0.0001 as `"<0.0001"`, though another minimum display p-value can be specified [@R-prettyunits].

```{r}
#| label: stattest-ttest-ex2-gt
@@ -372,7 +372,7 @@ tidy(ttest_ex3) %>%
print_gt_book(knitr::opts_current$get()[["label"]])
```

The results indicate that the difference in electrical bills for those who used A/C and those who did not is, on average, \$`r round(ttest_ex3$estimate,2)`. The difference appears to be statistically significant as the t-statistic is `r signif(ttest_ex3$statistic, 3)` and the p-value is `r pretty_p_value(ttest_ex3[["p.value"]])`. Households that used A/C spent, on average, $`r round(ttest_ex3[["estimate"]], 2) %>% unname()` more in 2020 on electricity than households without A/C.
The results in Table \@ref(tab:stattest-ttest-ex3-gt-tab) indicate that the difference in electrical bills for those who used A/C and those who did not is, on average, \$`r round(ttest_ex3$estimate,2)`. The difference appears to be statistically significant as the t-statistic is `r signif(ttest_ex3$statistic, 3)` and the p-value is `r pretty_p_value(ttest_ex3[["p.value"]])`. Households that used A/C spent, on average, $`r round(ttest_ex3[["estimate"]], 2) %>% unname()` more in 2020 on electricity than households without A/C.
\index{t-test!unpaired two-sample t-test|)}

#### Example 4: Paired two-sample t-test {.unnumbered #stattest-ttest-ex4}
@@ -419,7 +419,7 @@ tidy(ttest_ex4) %>%
```

\index{p-value|(}
U.S. households set their thermostat on average `r signif(ttest_ex4$estimate,2)`$^\circ$F warmer in summer nights than winter nights, which is statistically significant (t = `r signif(ttest_ex4$statistic, 3)`, p-value is `r pretty_p_value(ttest_ex4[["p.value"]])`). \index{Functions in survey!svyttest|)} \index{Residential Energy Consumption Survey (RECS)|(} \index{p-value|)} \index{t-test|)} \index{t-test!two-sample t-test|(} \index{t-test!paired two-sample t-test|(}
The results displayed in Table \@ref(tab:stattest-ttest-ex4-gt-tab) indicate that U.S. households set their thermostat on average `r signif(ttest_ex4$estimate,2)`$^\circ$F warmer in summer nights than winter nights, which is statistically significant (t = `r signif(ttest_ex4$statistic, 3)`, p-value is `r pretty_p_value(ttest_ex4[["p.value"]])`). \index{Functions in survey!svyttest|)} \index{Residential Energy Consumption Survey (RECS)|(} \index{p-value|)} \index{t-test|)} \index{t-test!two-sample t-test|(} \index{t-test!paired two-sample t-test|(}

## Chi-squared tests {#stattest-chi}

@@ -739,7 +739,7 @@ chi_ex2_obs_table %>%
print_gt_book(knitr::opts_current$get()[["label"]])
```

Both methods produce the same output as the `svychisq()` function. However, calculating the proportions directly from the design object allows us to obtain the variance information. In this case, the table output displays the survey estimate followed by the confidence intervals. Based on the output, we can see that of those who never trust people, `r round(chi_ex2$observed[5,5]/sum(chi_ex2$observed[,5])*100, 1)`% also never trust the government, while the proportions of never trusting the government are much lower for each of the other levels of trusting people. \index{gt package|)}
Both methods produce the same output as the `svychisq()` function. However, calculating the proportions directly from the design object allows us to obtain the variance information. In this case, the output in Table \@ref(tab:stattest-chi-ex2-prop2-tab) displays the survey estimate followed by the confidence intervals. Based on the output, we can see that of those who never trust people, `r round(chi_ex2$observed[5,5]/sum(chi_ex2$observed[,5])*100, 1)`% also never trust the government, while the proportions of never trusting the government are much lower for each of the other levels of trusting people. \index{gt package|)}

We may find it easier to look at these proportions graphically. We can use `ggplot()` and facets to provide an overview to create Figure \@ref(fig:stattest-chi-ex2-graph) below:

@@ -844,7 +844,7 @@ chi_ex3_obs_table %>%
print_gt_book(knitr::opts_current$get()[["label"]])
```

We can see that the age group distribution that voted for Biden and other candidates was younger than those that voted for Trump. For example, of those who voted for Biden, 20.4% were in the 18--29 age group, compared to only 11.4% of those who voted for Trump were in that age group. Conversely, 23.4% of those who voted for Trump were in the 50--59 age group compared to only 15.4% of those who voted for Biden. \index{Functions in survey!svychisq|)} \index{Chi-squared test|)} \index{American National Election Studies (ANES)|)} \index{Statistical testing|)}
In Table \@ref(tab:stattest-chi-ex3-tab) we can see that the age group distribution that voted for Biden and other candidates was younger than those that voted for Trump. For example, of those who voted for Biden, 20.4% were in the 18--29 age group, compared to only 11.4% of those who voted for Trump were in that age group. Conversely, 23.4% of those who voted for Trump were in the 50--59 age group compared to only 15.4% of those who voted for Biden. \index{Functions in survey!svychisq|)} \index{Chi-squared test|)} \index{American National Election Studies (ANES)|)} \index{Statistical testing|)}

\index{Chi-squared test!Test of homogeneity|)}

0 comments on commit 2ba717b

Please sign in to comment.