The fitting_problem()
function is the first step for fitting a reference
sample to known control totals with MultiLevelIPF.
All algorithms (see ml_fit()
) expect an object created by this function (or
optionally processed with flatten_ml_fit_problem()
).
The special_field_names()
function is useful for the field_names
argument
to fitting_problem
.
fitting_problem( ref_sample, controls = list(individual = individual_controls, group = group_controls), field_names, individual_controls, group_controls, prior_weights = NULL ) is.fitting_problem(x) # S3 method for fitting_problem format(x, ...) # S3 method for fitting_problem print(x, ...) special_field_names( groupId, individualId, individualsPerGroup = NULL, count = NULL )
ref_sample | The reference sample |
---|---|
controls | Control totals, by default initialized from the
|
field_names | Names of special fields, construct using
|
individual_controls, group_controls | Control totals at individual and group level, given as a list of data frames where each data frame defines a control |
prior_weights | Prior (or design) weights at group level; by default a vector of ones will be used, which corresponds to random sampling of groups |
x | An object |
... | Ignored. |
groupId, individualId | Name of the column that defines the ID of the group or the individual |
individualsPerGroup | Obsolete. |
count | Name of control total column in control tables (use first numeric column in each control by default). |
An object of class fitting_problem
, essentially a named list
with the following components:
refSample
The reference sample, a data.frame
.
controls
A named list with two components, individual
and group
. Each contains a list of controls as data.frame
s.
fieldNames
A named list with the names of special fields.
# Create example from Ye et al., 2009 # Provide reference sample ye <- tibble::tribble( ~HHNR, ~APER, ~HH_VAR, ~P_VAR, 1, 3, 1, 1, 1, 3, 1, 2, 1, 3, 1, 3, 2, 2, 1, 1, 2, 2, 1, 3, 3, 3, 1, 1, 3, 3, 1, 1, 3, 3, 1, 2, 4, 3, 2, 1, 4, 3, 2, 3, 4, 3, 2, 3, 5, 3, 2, 2, 5, 3, 2, 2, 5, 3, 2, 3, 6, 2, 2, 1, 6, 2, 2, 2, 7, 5, 2, 1, 7, 5, 2, 1, 7, 5, 2, 2, 7, 5, 2, 3, 7, 5, 2, 3, 8, 2, 2, 1, 8, 2, 2, 2 ) ye#> # A tibble: 23 x 4 #> HHNR APER HH_VAR P_VAR #> <dbl> <dbl> <dbl> <dbl> #> 1 1 3 1 1 #> 2 1 3 1 2 #> 3 1 3 1 3 #> 4 2 2 1 1 #> 5 2 2 1 3 #> 6 3 3 1 1 #> 7 3 3 1 1 #> 8 3 3 1 2 #> 9 4 3 2 1 #> 10 4 3 2 3 #> # … with 13 more rows#> # A tibble: 2 x 2 #> HH_VAR N #> <dbl> <dbl> #> 1 1 35 #> 2 2 65# Specify control at person level ye_ind <- tibble::tribble( ~P_VAR, ~N, 1, 91, 2, 65, 3, 104 ) ye_ind#> # A tibble: 3 x 2 #> P_VAR N #> <dbl> <dbl> #> 1 1 91 #> 2 2 65 #> 3 3 104ye_problem <- fitting_problem( ref_sample = ye, field_names = special_field_names( groupId = "HHNR", individualId = "PNR", count = "N" ), group_controls = list(ye_hh), individual_controls = list(ye_ind) ) ye_problem#> An object of class fitting_problem #> Reference sample: 23 observations #> Control totals: 1 at individual, and 1 at group level#> [1] 8.937470 8.937470 8.937470 23.448579 23.448579 2.613950 2.613950 #> [8] 2.613950 25.899223 25.899223 25.899223 14.347802 14.347802 14.347802 #> [15] 11.009562 11.009562 2.733852 2.733852 2.733852 2.733852 2.733852 #> [22] 11.009562 11.009562