moe_crosstab_3way: weighted 3-way crosstabs with margin of error

Description Usage Arguments Details Value Examples

View source: R/moeCrosstab3way.R

Description

moe_crosstab_3way returns a tibble containing a weighted crosstab of two variables by a third variable with margin of error

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
moe_crosstab_3way(
  df,
  x,
  y,
  z,
  weight,
  remove = c(""),
  n = TRUE,
  pct_type = "row",
  format = "long",
  zscore = 1.96,
  unwt_n = FALSE
)

Arguments

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

Details

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.

Value

a tibble

Examples

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")

Example output

# 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       Fema7.01   30.5           18.0   9.25   22.5
3 Widow/divorcMale        14.9    35.7           20.6   7.64   13.6
4 Widow/divorcFema17.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 Fema10.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>

pollster documentation built on Aug. 25, 2020, 5:08 p.m.