Description Usage Arguments Details Value Examples
View source: R/moeCrosstab3way.R
moe_crosstab_3way
returns a tibble containing a weighted crosstab of two variables by a third variable with margin of error
1 2 3 4 5 6 7 8 9 10 11 12 13 |
df |
The data source |
x |
The independent variable |
y |
The dependent variable |
z |
The second control variable |
weight |
The weighting variable |
remove |
An optional character vector of values to remove from final table (e.g. "refused"). This will not affect any calculations made. The vector is not case-sensitive. |
n |
logical, if TRUE numeric totals are included. |
pct_type |
Controls the kind of percentage values returned. One of "row" or "cell." |
format |
one of "long" or "wide" |
zscore |
defaults to 1.96, consistent with a 95% confidence interval |
unwt_n |
logical, if TRUE it adds a column with unweighted frequency values |
Options include row or cell percentages. The tibble can be in long or wide format. These tables are ideal for use with small multiples created with ggplot2::facet_wrap.
a tibble
1 2 3 | moe_crosstab_3way(df = illinois, x = sex, y = educ6, z = maritalstatus, weight = weight)
moe_crosstab_3way(df = illinois, x = sex, y = educ6, z = maritalstatus, weight = weight,
format = "wide")
|
# A tibble: 36 x 6
maritalstatus sex educ6 pct moe n
<fct> <fct> <fct> <dbl> <dbl> <dbl>
1 Married Male LT HS 8.63 0.568 28011171.
2 Married Male HS 29.9 0.927 28011171.
3 Married Male Some Col 17.2 0.764 28011171.
4 Married Male AA 7.99 0.549 28011171.
5 Married Male BA 21.8 0.836 28011171.
6 Married Male Post-BA 14.4 0.711 28011171.
7 Married Female LT HS 7.01 0.520 26990616.
8 Married Female HS 30.5 0.936 26990616.
9 Married Female Some Col 18.0 0.782 26990616.
10 Married Female AA 9.25 0.589 26990616.
# … with 26 more rows
# A tibble: 6 x 15
maritalstatus sex `pct_LT HS` pct_HS `pct_Some Col` pct_AA pct_BA
<fct> <fct> <dbl> <dbl> <dbl> <dbl> <dbl>
1 Married Male 8.63 29.9 17.2 7.99 21.8
2 Married Fema… 7.01 30.5 18.0 9.25 22.5
3 Widow/divorc… Male 14.9 35.7 20.6 7.64 13.6
4 Widow/divorc… Fema… 17.7 35.2 20.2 8.37 11.4
5 Never Married Male 12.6 31.3 27.2 6.51 17.9
6 Never Married Fema… 10.3 25.0 29.9 7.27 20.0
# … with 8 more variables: `pct_Post-BA` <dbl>, `moe_LT HS` <dbl>,
# moe_HS <dbl>, `moe_Some Col` <dbl>, moe_AA <dbl>, moe_BA <dbl>,
# `moe_Post-BA` <dbl>, n <dbl>
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.