compute_margins: Compute margins for a weighting of a multi-level fitting...

Description Usage Arguments Details Value See Also Examples

View source: R/margins.R

Description

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

Usage

1
2
3
compute_margins(ml_problem, weights, verbose = FALSE)

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

Arguments

ml_problem

A fitting problem created by ml_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 ml_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 ml_problem() function), based on a reference sample and a weight vector.

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

Value

compute_margins() returns a named list with two components, individual and group. Each contains a list of margins as data.frames.

margins_to_df() returns a data frame with the following columns:

..control.type..

Type of the control total: either individual or group.

..control.name..

Name of the control total, if exists.

..id..

Name of the control category.

..count..

Count of the control category.

See Also

ml_fit()

Examples

1
2
3
4
5
6
7
8
path <- toy_example("Tiny")
problem <- readRDS(path)
fit <- ml_fit(ml_problem = problem, algorithm = "entropy_o")
margins <- compute_margins(problem, fit$weights)
margins

margin_to_df(problem$controls)
margin_to_df(margins)

mlfit documentation built on Oct. 8, 2021, 9:09 a.m.