Skip to content

Commit

Permalink
Final minor formatting fixes. (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
rpowell22 authored Apr 30, 2024
1 parent ecec950 commit 3ff07d4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions 05-descriptive-analysis.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ recs_des %>%
group_by(Region, Division) %>%
survey_tally(name = "N")
```
\index{Functions in srvyr!survey\_count}|)} \index{Cross-tabulation|)}
\index{Functions in srvyr!survey\_count|)} \index{Cross-tabulation|)}

## Totals and sums \index{Functions in srvyr!survey\_total|(} \index{survey\_total|see {Functions in srvyr}}

Expand Down Expand Up @@ -475,7 +475,8 @@ recs_des %>%

When specifying multiple variables, the proportions are conditional. In the results above, notice that the proportions sum to 1 within each region. This can be interpreted as the proportion of housing units with A/C *within* each region. For example, in the Northeast region, approximately `r scales::percent(recs_des %>% group_by(Region, ACUsed) %>% summarize(p = survey_prop()) %>% filter(Region == "Northeast", ACUsed == "FALSE") %>% pull(p), accuracy = 0.1)` of housing units don't have A/C, while around `r scales::percent(recs_des %>% group_by(Region, ACUsed) %>% summarize(p = survey_prop()) %>% filter(Region == "Northeast", ACUsed == "TRUE") %>% pull(p), accuracy = 0.1)` have A/C.

#### Example 3: Joint proportions {.unnumbered} \index{Functions in srvyr!interact|(} \index{interact|see {Functions in srvyr}}
#### Example 3: Joint proportions {.unnumbered}
\index{Functions in srvyr!interact|(} \index{interact|see {Functions in srvyr}}

If we're interested in a joint proportion, we use the `interact()` function. In the example below, we apply the `interact()` function to `Region` and `ACUsed`:

Expand Down Expand Up @@ -1072,7 +1073,9 @@ recs_des %>%
For the values less than 1 (`BTUEL_deff` and `BTUFO_deff`), the results suggest that the survey design is more efficient than a simple random sample. For the values greater than 1 (`BTUNG_deff`, `BTULP_deff`, and `BTUWOOD_deff`), the results indicate that the survey design is less efficient than a simple random sample.

\index{Design effect|)}

### Creating summary rows

\index{Functions in srvyr!cascade|(} \index{cascade|see {Functions in srvyr}}

When using `group_by()` in analysis, the results are returned with a row for each group or combination of groups. Often, we want both the breakdowns by group and a summary row for the estimate representing the entire population. For example, we may want the average electricity consumption by region *and* nationally. The {srvyr} package has the convenient `cascade()` function, which adds summary rows for the total of a group. It is used instead of `summarize()` and has similar functionalities along with some additional features.
Expand Down
4 changes: 2 additions & 2 deletions 08-communicating-results.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Although discussing key findings in the text is important, presenting large amou

Tables are a great way to provide a large amount of data when individual data points need to be examined. However, it is important to present tables in a reader-friendly format. Numbers should align, rows and columns should be easy to follow, and the table size should not compromise readability. Using key visualization techniques, we can create tables that are informative and nice to look at. \index{gt package|(}Many packages create easy-to-read tables (e.g., {kable} \+ {kableExtra}, {gt}, {gtsummary}, {DT}, {formattable}, {flextable}, {reactable}.) We appreciate the flexibility, ability to use pipes (e.g., `%>%`), and numerous extensions of the {gt} package. While we focus on {gt} here, we encourage learning about others as they may have additional helpful features.\index{gt package|)} \index{Replicate weights|(}\index{gtsummary|(} Please note, at this time, {gtsummary} needs additional features to be widely used for survey analysis, particularly due to its lack of ability to work with replicate designs.\index{Replicate weights|)} We provide one example using {gtsummary} and hope it evolves into a more comprehensive tool over time.\index{gtsummary|)}

#### Transitioning {srvyr} output to a {gt} table {-} {#results-gt}
#### Transitioning {srvyr} output to a {gt} table {-}

\index{American National Election Studies (ANES)|(} \index{gt package|(}
Let's start by using some of the data we calculated earlier in this book. In Chapter \@ref(c06-statistical-testing), we looked at data on trust in government with the proportions calculated below: \index{Functions in srvyr!survey\_prop|(} \index{Functions in srvyr!summarize|(} \index{Functions in srvyr!drop\_na}
Expand Down Expand Up @@ -291,7 +291,7 @@ anes_des_gtsum2 %>%
print_gt_book(knitr::opts_current$get()[["label"]])
```

Table \@ref(tab:results-gts-ex-2-tab) is closer to our ideal output, but we still want to make a few changes. To exclude the term "Characteristic" and the estimated population size (N), we can modify the header using the `modify_header()` function to update the `label`. Further adjustments can be made based on personal preferences, organizational guidelines, or other style guides. If we prefer having the standard error in the header, similar to the {gt} table, instead of in the footnote (the {gtsummary} default), we can make these changes by specifying `stat_0` in the `modify_header()` function. Additionally, using `modify_footnote()` with `update = everything() ~ NA` removes the standard error from the footnote. After transforming the object into a {gt} table using `as_gt()`, we can add footnotes and a title using the same methods explained in Section \@ref(results-gt). This updated table is displayed in Table \@ref(tab:results-gts-ex-3-tab).
Table \@ref(tab:results-gts-ex-2-tab) is closer to our ideal output, but we still want to make a few changes. To exclude the term "Characteristic" and the estimated population size (N), we can modify the header using the `modify_header()` function to update the `label`. Further adjustments can be made based on personal preferences, organizational guidelines, or other style guides. If we prefer having the standard error in the header, similar to the {gt} table, instead of in the footnote (the {gtsummary} default), we can make these changes by specifying `stat_0` in the `modify_header()` function. Additionally, using `modify_footnote()` with `update = everything() ~ NA` removes the standard error from the footnote. After transforming the object into a {gt} table using `as_gt()`, we can add footnotes and a title using the same methods explained in the previous section. This updated table is displayed in Table \@ref(tab:results-gts-ex-3-tab).

```{r}
#| label: results-gts-ex-3
Expand Down

0 comments on commit 3ff07d4

Please sign in to comment.