These functions allows checking a fit in terms of the original input data.

compute_margins(fitting_problem, weights, verbose = FALSE)

margin_to_df(controls, count = NULL, verbose = FALSE)

Arguments

fitting_problem

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

weights

A vector with one entry per row of the original reference sample

verbose

If TRUE, print diagnostic output.

controls

Margins as returned by compute_margins or as passed to the controls parameter of fitting_problem().

count

Name of control total column, autodetected by default.

Details

compute_margins() computes margins in the format used for the input controls (i.e., as expected by the controls parameter of the fitting_problem() function), based on a reference sample and a weights vector.

margins_to_df() converts margins to a data frame for easier comparison.

See also

Examples

path <- toy_example("Tiny") problem <- readRDS(path) fit <- ml_fit(algorithm = "entropy_o", fitting_problem = problem) margins <- compute_margins(problem, fit$weights) margins
#> $individual #> $individual$IND #> WKSTAT N #> 1 1 91 #> 2 2 65 #> 3 3 104 #> #> #> $group #> $group$GROUP #> CAR N #> 1 0 35 #> 2 1 65 #> #>
margin_to_df(problem$controls)
#> ..control.type.. ..control.name.. ..id.. ..count.. #> 1 individual IND 1 91 #> 2 individual IND 2 65 #> 3 individual IND 3 104 #> 4 group GROUP 0 35 #> 5 group GROUP 1 65
margin_to_df(margins)
#> ..control.type.. ..control.name.. ..id.. ..count.. #> 1 individual IND 1 91 #> 2 individual IND 2 65 #> 3 individual IND 3 104 #> 4 group GROUP 0 35 #> 5 group GROUP 1 65