flatten_ml_fit_problem: Return a flattened representation of a multi-level fitting...

View source: R/flatten_ml_fit_problem.R

flatten_ml_fit_problemR Documentation

Return a flattened representation of a multi-level fitting problem instance

Description

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.

Usage

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

as_flat_ml_fit_problem(x, model_matrix_type = c("combined", "separate"), ...)

Arguments

ml_problem

A fitting problem created by ml_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

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.

Value

An object of classes flat_ml_fit_problem, essentially a named list.

See Also

ml_fit()

Examples

path <- toy_example("Tiny")
flat_problem <- flatten_ml_fit_problem(ml_problem = readRDS(path))
flat_problem

fit <- ml_fit_dss(flat_problem)
fit$flat_weights
fit$weights

krlmlr/MultiLevelIPF documentation built on Feb. 4, 2024, 9:21 a.m.