This function serves as an interface to the jomo
package and supports imputation of multilevel continuous and categorical data.
In order for categorical variables to be detected correctly, these must be formatted as a factor
variables (see examples).
The imputation model can be specified using either the type
or the formula
argument.
The type
interface is designed to provide quick-and-easy imputations using jomo
. The type
argument must be an integer vector denoting the role of each variable in the imputation model:
1
: target variables containing missing data
2
: predictors with fixed effect on all targets (completely observed)
3
: predictors with random effect on all targets (completely observed)
-1
: grouping variable within which the imputation is run separately
-2
: cluster indicator variable
0
: variables not featured in the model
At least one target variable and the cluster indicator must be specified.
The intercept is automatically included both as a fixed and random effect.
If a variable of type -1
is found, then separate imputations are performed within each level of that variable.
The formula
argument is intended as more flexible and feature-rich interface to jomo
. Specifying the formula
argument is similar to specifying other formulae in R.
Given below is a list of operators that jomoImpute
currently understands:
~
: separates the target (left-hand) and predictor (right-hand) side of the model
+
: adds target or predictor variables to the model
*
: adds an interaction term of two or more predictors
|
: denotes cluster-specific random effects and specifies the cluster indicator (i.e., 1|ID
)
I()
: defines functions to be interpreted by model.matrix
Predictors are allowed to have fixed effects, random effects, or both on all target variables.
The intercept is automatically included both as a fixed and a random effect, but it can be constrained if necessary (see panImpute
).
Note that, when specifying random effects other than the intercept, these will not be automatically added as fixed effects and must be included explicitly.
Any predictors defined by I()
will be used for imputation but not included in the data set unless save.pred=TRUE
.
If missing data occur at both levels of the sample (level 1 and level 2), then a list of two formula
s or type
s may be provided.
The first element of this list denotes the imputation model for variables at level 1.
The second element denotes the imputation model for variables at level 2.
In such a case, missing values are imputed jointly at both levels (see examples, see also Carpenter and Kenward, 2013; Goldstein et al., 2009).
It is possible to model the covariance matrix of residuals at level 1 as random across clusters (Yucel, 2011; Carpenter & Kenward, 2013).
The random.L1
argument determines this behavior and how the values of these matrices are stored.
If set to "none"
, a common covariance matrix is assumed across groups (similar to panImpute
).
If set to "mean"
, the covariance matrices are random, but only the average covariance matrix is stored at each iteration.
If set to "full"
, the covariance matrices are random, and all variances and covariances from all clusters are stored.
In order to run separate imputations for each level of an additional grouping variable, the group
argument may be used.
The name of the grouping variable must be given in quotes.
As a default prior, jomoImpute
uses "least informative" inverse-Wishart priors for the covariance matrix of random effects (and residuals at level 2) and the covariance matrix of residuals at level 1, that is, with minimum degrees of freedom (largest dispersion) and identity matrices for scale.
For better control, the prior
argument may be used for specifying alternative prior distributions.
These must be supplied as a list containing the following components:
Binv
: scale matrix for the covariance matrix of residuals at level 1
Dinv
: scale matrix for the covariance matrix of random effects and residuals at level 2
a
: starting value for the degrees of freedom of random covariance matrices of residuals (only used with random.L1="mean"
or random.L1="full"
)
Note that jomo
does not allow for the degrees of freedom for the inverse-Wishart prior to be specified by the user.
These are always set to the lowest value possible (largest dispersion) or determined iteratively if the residuals at level 1 are modeled as random (see above).