The default topline table comes with columns for response category, frequency count, percent, valid percent, and cumulative percent.
|Response||Frequency||Percent||Valid Percent||Cumulative Percent|
Because the output is a
tibble, it’s simple to manipulate it in any way you want after creating it. Use
dplyr::select to remove columns or
dplyr::filter to remove rows. For convenience, the
topline function also provides ways to do this within the function call. For example, the
remove argument accepts a character vector of response values to be removed from the table after all statistics are calculated. This is especially useful for survey data with a “refused” category.
|Response||Frequency||Valid Percent||Cumulative Percent|
Refer to the
kableExtra package for lots of examples on how to format the appearance of these tables in either HTML or PDF latex formats. I recommend the vignettes “Create Awesome HTML Table with knitr::kable and kableExtra” and "Create Awesome PDF Table with knitr::kable and kableExtra.
Get at topline table with the margin of error in a separate column using the
moe_topline function. By default, a z-score of 1.96 (95% confidence interval is used). Supply your own desired z-score using the
moe_topline(df = illinois, variable = educ6, weight = weight) #> # A tibble: 6 x 6 #> Response Frequency Percent `Valid Percent` MOE `Cumulative Percent` #> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 LT HS 10770999. 10.5 10.5 0.326 10.5 #> 2 HS 31409418. 30.6 30.6 0.490 41.1 #> 3 Some Col 21745113. 21.2 21.2 0.435 62.3 #> 4 AA 8249909. 8.03 8.03 0.289 70.3 #> 5 BA 19937965. 19.4 19.4 0.421 89.7 #> 6 Post-BA 10565110. 10.3 10.3 0.323 100
The margin of error is calculated including the design effect of the sample weights, using the following formula:
The design effect is calculated using the formula