| Title: | Multiple Imputation Using the General Location Model with the EMB Algorithm |
|---|---|
| Description: | Provides multiple imputation for mixed continuous and categorical data using the General Location Model (Olkin and Tate (1961) <doi:10.1214/aoms/1177705052>; Little and Schluchter (1985) <doi:10.1093/biomet/72.3.497>) combined with the Expectation-Maximization with Bootstrapping (EMB) algorithm of Honaker, King and Blackwell (2011) <doi:10.18637/jss.v045.i07>. Categorical variables are specified via the noms option; all other variables are treated as continuous. The package wraps the EM implementation in the 'mix' package and extends it with a bootstrap wrapper to produce proper multiple imputations in the sense of Rubin (1987, ISBN:978-0-471-08705-2). |
| Authors: | Paul Allison [aut, cre] |
| Maintainer: | Paul Allison <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.4 |
| Built: | 2026-10-15 20:43:00 UTC |
| Source: | https://github.com/cran/glemb |
Converts a glemb object to the mids format used by the mice package,
enabling use of mice::pool() for results pooling.
as.mids.glemb(x, data, ...)as.mids.glemb(x, data, ...)
x |
A |
data |
The original incomplete data frame that was passed to |
... |
Ignored. |
The function stacks the original data (as imputation 0) and all m
imputed datasets in long format, adds .imp and .id columns, and
calls mice::as.mids() to construct the mids object.
A mids object.
if (requireNamespace("mice", quietly = TRUE)) { imp <- glemb(nlsymiss, m = 5, noms = c(race, pov, momwork, divorce, gender), output = "list", seed = 1) mids_obj <- as.mids.glemb(imp, data = nlsymiss) fit <- with(mids_obj, lm(anti ~ self + pov + race + childage + divorce + gender + momwork)) mice::pool(fit) }if (requireNamespace("mice", quietly = TRUE)) { imp <- glemb(nlsymiss, m = 5, noms = c(race, pov, momwork, divorce, gender), output = "list", seed = 1) mids_obj <- as.mids.glemb(imp, data = nlsymiss) fit <- with(mids_obj, lm(anti ~ self + pov + race + childage + divorce + gender + momwork)) mice::pool(fit) }
glemb() performs multiple imputation of mixed continuous and categorical
data using the General Location Model (GLM) combined with the
Expectation-Maximization with Bootstrapping (EMB) algorithm.
glemb( data, m = 20L, noms = NULL, idvars = NULL, cat.interact = 2L, cat.prior = NULL, empri = NULL, maxits = 1000L, seed = NULL, output = "mids", max.cells = 500000L, meanmodel = "main", p2s = 1L )glemb( data, m = 20L, noms = NULL, idvars = NULL, cat.interact = 2L, cat.prior = NULL, empri = NULL, maxits = 1000L, seed = NULL, output = "mids", max.cells = 500000L, meanmodel = "main", p2s = 1L )
data |
A data frame containing the data to be imputed. All variables
not listed in |
m |
Positive integer. Number of imputed datasets to generate.
Default is |
noms |
Variable names to treat as categorical (nominal) in the
imputation model. Can be supplied quoted or unquoted:
|
idvars |
Character vector of column names to be carried through to the
output unchanged but excluded from the imputation model. Typically used
for subject or case identifiers. Default is |
cat.interact |
Integer, either |
cat.prior |
Numeric scalar or |
empri |
Numeric scalar or |
maxits |
Positive integer. Maximum number of ECM iterations allowed
per bootstrap sample. Default is |
seed |
Positive integer or |
output |
Character scalar. |
max.cells |
Positive integer or |
meanmodel |
Character scalar. Controls the parameterisation of the
within-cell continuous variable means. |
p2s |
Integer, |
The General Location Model (Olkin & Tate 1961; Little & Schluchter 1985) factorises the joint distribution of continuous variables y and categorical variables x as:
The categorical margin is modelled with a log-linear
model restricted to at most cat.interact-way interactions among the
categorical variables. The continuous conditional
is multivariate normal with a
covariance matrix shared across all cells. How the cell means are
parameterised depends on meanmodel. With "main" (default) the mean of
each continuous variable depends on an intercept plus the main effects of
the categorical variables — the same parameterisation as a standard
regression with dummy variables. With "saturated" each cell has its own
unrestricted mean vector. Both models imply that the conditional mean of
every continuous variable is a linear function of all other variables; the
saturated model additionally allows all interactions among the categorical
variables to enter the means. The conditional distribution of every
categorical variable is a logistic regression function of all the other
variables.
Proper multiple imputations are generated via the EMB algorithm (Honaker, King & Blackwell 2011):
Draw a bootstrap sample (with replacement) from the incomplete data.
Run the ECM algorithm (mix::ecm.mix()) on the bootstrap sample to
obtain parameter estimates.
Draw one set of imputed values from the posterior predictive
distribution given those parameters (mix::imp.mix()).
Repeat steps 1–3 m times to produce m completed datasets.
When the number of cells in the multiway table for the categorical variables
is large relative to sample size, some cells may contain few or no
observations. A Dirichlet prior (controlled by cat.prior) is applied by
adding cat.prior pseudo-observations per cell to the bootstrap sample
before estimation. glemb() warns when the number of cells exceeds
n / 5.
An object of class "glemb", which is a list with components:
imputationsA list of m completed data frames.
mNumber of imputations.
callThe matched call.
categoricalNames of variables treated as categorical.
continuousNames of variables treated as continuous.
idvarsNames of ID variables excluded from the imputation model.
cat.interactInteraction order used in the log-linear model.
cat.priorDirichlet pseudocount used (after automatic selection if applicable).
empriRidge prior strength used (after automatic selection if applicable).
maxitsMaximum ECM iterations per bootstrap sample.
seedSeed used, or NULL.
meanmodelMean model used: "main" or "saturated".
Olkin, I. & Tate, R.F. (1961). Multivariate correlation models with mixed discrete and continuous variables. Annals of Mathematical Statistics, 32, 448–465. doi:10.1214/aoms/1177705052
Little, R.J.A. & Schluchter, M.D. (1985). Maximum likelihood estimation for mixed continuous and categorical data with missing values. Biometrika, 72, 497–512. doi:10.1093/biomet/72.3.497
Honaker, J., King, G. & Blackwell, M. (2011). Amelia II: A program for missing data. Journal of Statistical Software, 45(7), 1–47. doi:10.18637/jss.v045.i07
Schafer, J.L. (1997). Analysis of Incomplete Multivariate Data. Chapman & Hall.
print.glemb(), summary.glemb(), as.mids.glemb()
# Impute the NLSY data, treating five variables as categorical imp <- glemb(nlsymiss, m = 5, noms = c(race, pov, momwork, divorce, gender), seed = 123) # Fit a regression to each completed dataset and pool the results if (requireNamespace("mice", quietly = TRUE)) { fit <- with(imp, lm(anti ~ self + pov + race + childage + divorce + gender + momwork)) summary(mice::pool(fit)) } # Quoted names work too; output = "list" returns a glemb object imp <- glemb(nlsymiss, m = 5, noms = c("race", "pov", "momwork", "divorce", "gender"), output = "list", seed = 123) head(imp$imputations[[3]]) # Allow three-way interactions among categorical variables imp <- glemb(nlsymiss, m = 5, noms = c(race, pov, momwork), cat.interact = 3, output = "list", seed = 123) # Use a saturated mean model (cell-specific intercepts; more flexible, # requires more data) imp <- glemb(nlsymiss, m = 5, noms = c(race, pov, momwork), meanmodel = "saturated", output = "list", seed = 123)# Impute the NLSY data, treating five variables as categorical imp <- glemb(nlsymiss, m = 5, noms = c(race, pov, momwork, divorce, gender), seed = 123) # Fit a regression to each completed dataset and pool the results if (requireNamespace("mice", quietly = TRUE)) { fit <- with(imp, lm(anti ~ self + pov + race + childage + divorce + gender + momwork)) summary(mice::pool(fit)) } # Quoted names work too; output = "list" returns a glemb object imp <- glemb(nlsymiss, m = 5, noms = c("race", "pov", "momwork", "divorce", "gender"), output = "list", seed = 123) head(imp$imputations[[3]]) # Allow three-way interactions among categorical variables imp <- glemb(nlsymiss, m = 5, noms = c(race, pov, momwork), cat.interact = 3, output = "list", seed = 123) # Use a saturated mean model (cell-specific intercepts; more flexible, # requires more data) imp <- glemb(nlsymiss, m = 5, noms = c(race, pov, momwork), meanmodel = "saturated", output = "list", seed = 123)
A subsample of 581 children interviewed in 1990 as part of the National Longitudinal Survey of Youth (NLSY), used as a running example in Allison (2001). Five of the nine variables have missing values, and only 225 cases are complete. The data mix continuous and categorical variables, which makes them a natural application of the General Location Model.
nlsymissnlsymiss
A data frame with 581 rows and 9 variables:
Antisocial behavior score (0–6).
Self-esteem score (9–24); 148 missing.
Family in poverty (1 = yes, 0 = no); 150 missing.
Child's age in years.
Mother divorced (1 = yes, 0 = no).
Child's gender (1 = female, 0 = male).
Mother's age at the child's birth.
Mother employed (1 = yes, 0 = no); 86 missing.
Race/ethnicity: 1 = neither Black nor Hispanic, 2 = Black, 3 = Hispanic; 113 missing.
U.S. Bureau of Labor Statistics, National Longitudinal Survey of Youth, Children data, 1990.
Allison, P.D. (2001). Missing Data. Sage Publications.
summary(nlsymiss) colSums(is.na(nlsymiss))summary(nlsymiss) colSums(is.na(nlsymiss))
Print a glemb object
## S3 method for class 'glemb' print(x, digits = 3L, ...)## S3 method for class 'glemb' print(x, digits = 3L, ...)
x |
A |
digits |
Integer. Number of decimal places for numeric values.
Default is |
... |
Ignored. |
x, invisibly.
imp <- glemb(nlsymiss, m = 5, noms = c(race, pov, momwork, divorce, gender), output = "list", seed = 1) print(imp)imp <- glemb(nlsymiss, m = 5, noms = c(race, pov, momwork, divorce, gender), output = "list", seed = 1) print(imp)
Prints a summary of the imputation model and the missingness in the first imputed dataset.
## S3 method for class 'glemb' summary(object, digits = 3L, ...)## S3 method for class 'glemb' summary(object, digits = 3L, ...)
object |
A |
digits |
Integer. Number of decimal places for numeric values.
Default is |
... |
Ignored. |
object, invisibly.
imp <- glemb(nlsymiss, m = 5, noms = c(race, pov, momwork, divorce, gender), output = "list", seed = 1) summary(imp)imp <- glemb(nlsymiss, m = 5, noms = c(race, pov, momwork, divorce, gender), output = "list", seed = 1) summary(imp)