This function transforms a multi-level fitting problem to a representation more suitable for applying the algorithms: A matrix with one row per controlled attribute and one column per household, a weight vector with one weight per household, and a control vector.

flatten_ml_fit_problem(
  fitting_problem,
  model_matrix_type = c("combined", "separate"),
  verbose = FALSE
)

as.flat_ml_fit_problem(x, model_matrix_type = c("combined", "separate"), ...)

Arguments

fitting_problem

A fitting problem created by fitting_problem() or returned by flatten_ml_fit_problem().

model_matrix_type

Which model matrix building strategy to use? See details.

verbose

If TRUE, print diagnostic output.

x

An object

...

Further parameters passed to the algorithm

Value

An object of classes flat_ml_fit_problem, essentially a named list.

Details

The standard way to build a model matrix (model_matrix = "combined") is to include intercepts and avoid repeating redundant attributes. A simpler model matrix specification, available via model_matrix = "separate", is suggested by Ye et al. (2009) and required for the ml_fit_ipu() implementation: Here, simply one column per target value is used, which results in a larger model matrix if more than one control is given.

See also

Examples

path <- toy_example("Tiny") flat_problem <- flatten_ml_fit_problem(fitting_problem = readRDS(path)) flat_problem
#> An object of class flat_ml_fit_problem #> Dimensions: 5 groups, 8 target values #> Model matrix type: combined #> Original fitting problem: #> An object of class fitting_problem #> Reference sample: 23 observations #> Control totals: 1 at individual, and 1 at group level #> Results for algorithms: entropy_o(1,0), entropy_o(0,1), entropy_o(1,1), entropy, ml_ipf, ipu
fit <- ml_fit_dss(flat_problem) fit$flat_weights
#> [1] 8.937470 23.448579 2.613950 25.899223 14.347802 11.009562 2.733852 #> [8] 11.009562 #> attr(,"success") #> [1] TRUE #> attr(,"iterations") #> [1] 6 #> attr(,"method") #> [1] "raking"
fit$weights
#> [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