Collapses survey data to get direct estimates (i.e. non-pooled sample porportions)

direct_ests(.formula, .data, area_var, weight_var = NULL, shape = "wide")

Arguments

.formula

MRP formula. Only thing that will be used is the outcome variable (a binary variable)

.data

Survey data to be collapsed

area_var

Character for the variable(s) that corresponds to the area to aggregate to.

weight_var

Character for the variable that corresponds to weights.

shape

Whether to return the output in "wide" (with one row per states) or "long" (one row per state x estimate). Defaults to "wide".

Value

A wide dataframe where each row is a area, p_raw indicates the raw average, p_wt indicates the weighted average (if weight_var is provided), and n_raw is the raw sample size. We also provide standard errors in the form se_se_raw follows the standard standard error for proportion sqrt(p*(1-p)/n). The se_wt implements the weighted standard error, where the sample size is replaced with the effective sample size, sum(wt)^2 / sum(wt^2).

Examples

 direct_ests(response ~ (1|cd), cces_GA,
             area_var = "cd",
             weight_var = "weight_post")
#> # A tibble: 14 × 7
#>    cd    p_raw  p_wt n_raw se_raw  n_wt  se_wt
#>    <chr> <dbl> <dbl> <int>  <dbl> <dbl>  <dbl>
#>  1 GA-01 0.506 0.463    85 0.0542  43.6 0.0755
#>  2 GA-02 0.537 0.635    67 0.0609  30.5 0.0872
#>  3 GA-03 0.359 0.319    78 0.0543  60.2 0.0601
#>  4 GA-04 0.717 0.678   127 0.0400  69.8 0.0559
#>  5 GA-05 0.730 0.796   111 0.0422  30.7 0.0727
#>  6 GA-06 0.559 0.560   102 0.0492  78.6 0.0560
#>  7 GA-07 0.46  0.418   100 0.0498  49.8 0.0699
#>  8 GA-08 0.295 0.407    61 0.0584  33.3 0.0851
#>  9 GA-09 0.265 0.207   102 0.0437  72.1 0.0477
#> 10 GA-10 0.406 0.461    96 0.0501  60.7 0.0640
#> 11 GA-11 0.425 0.401   127 0.0439  68.7 0.0591
#> 12 GA-12 0.368 0.391    76 0.0553  47.5 0.0708
#> 13 GA-13 0.545 0.495    99 0.0500  52.2 0.0692
#> 14 GA-14 0.2   0.218    75 0.0462  31.5 0.0736