Create long table for rake weighitng

rake_target(formula, poptable, newtable, area_var, count_var = "count")

Arguments

formula

A representation of the aggregate imputation or "outcome" model, of the form X_{K} ~ X_1 + ... X_{K - 1}

poptable

The population table, collapsed in terms of counts. Must contain all variables in the RHS of formula, as well as the variables specified in area_var and count_var below.

newtable

A dataset that contains marginal counts or proportions. Will be collapsed internally to get simple proportions.

area_var

A character vector of the area of interest.

count_var

A character variable that specifies which variable in poptable indicates the count

Value

A long table that, for each districts, list the target distribution of the outcome (variable = "outcome") and the cell of the known Xs (variable = "Xs). This is consistent with the dataframe format for targets in the autumn package https://github.com/aaronrudkin/autumn

Examples

library(dplyr)
#> 
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union
library(ccesMRPprep)

# suppose we want know the distribution of (age x female) and we know the
# distribution of (race), by CD, but we don't know the joint of the two.

race_target <- count(acs_race_NY, cd, race, wt = count, name = "count")

rake_target(race ~ age + female,
            poptable = acs_race_NY,
            newtable = race_target,
            area_var = "cd")
#> # A tibble: 432 × 4
#>    cd    variable label               proportion
#>    <chr> <chr>    <chr>                    <dbl>
#>  1 NY-01 Xs       18 to 24 years_0        0.0592
#>  2 NY-01 Xs       18 to 24 years_1        0.0565
#>  3 NY-01 Xs       25 to 34 years_0        0.0787
#>  4 NY-01 Xs       25 to 34 years_1        0.0734
#>  5 NY-01 Xs       35 to 44 years_0        0.0714
#>  6 NY-01 Xs       35 to 44 years_1        0.0733
#>  7 NY-01 Xs       45 to 64 years_0        0.182 
#>  8 NY-01 Xs       45 to 64 years_1        0.181 
#>  9 NY-01 Xs       65 years and over_0     0.0999
#> 10 NY-01 Xs       65 years and over_1     0.125 
#> # … with 422 more rows