These methods change the family, imputation method, size, type, and
so forth of a
missing_variable. They are typically
called immediately before calling
mi because they
affect how the conditional expectation of each
1 2 3 4 5 6 7 8
A character vector (typically) naming one or more
Typically a character string naming what is to be changed, such
Typically a character string naming what
Other arguments, not currently utilized
In order to run
mi correctly, data must first be specified to be ready for multiple imputation using the
missing_data.frame function. For each variable,
missing_data.frame will record information required by
mi: the variable's type, distribution family, and link function; whether a variable should be standardized or tranformed by a log function or square root; what specific model to use for the conditional distribution of the variable in the
mi algorithm and how to draw imputed values from this model; and whether additional rows (for the purposes of prediction) are required.
missing_data.frame will attempt to guess the correct type, family, and link for each variable based on its class in a regular
data.frame. These guesses can be checked with
show and adjusted if necessary with
change. Any further additions to the model in regards to variable transformations, custom conditional models, or extra non-observed predictive cases must be specified with
mi is run.
In general, most users will only use the
change will then call
change_type depending on what characteristic is specified with the
what option. The other change_* functions can be called directly but are primarily intended to be called indirectly by the change function.
what = "type"
Change the subclass of variable(s)
to should be a character vector whose elements are subclasses of the
missing_variable-class and are documented further there. Among the most commonly used subclasses are
what = "family"
Change the distribution family for variable(s)
to must be of class
family or a list where each element is of class
family. If a variable is of
binary-class, then the family must be
binomial (the default) or possibly
quasibinomial. If a variable is of
unordered-categorical-class, use the
multinomial family. If a variable is of
count-class, then the family must be
quasipoisson (the default) or
poisson. If a variable is continuous, there are more choices for its family, but
gaussian is the default and the others are not supported yet.
what = "link"
Change the link function for variable(s)
to can be any of the supported link functions for the existing family. See
family for details; however, not all of these link functions have appropriate
what = "model"
Change the conditional model for variable
y. It usually is not necessary to change the model, since it is actually determined by the class, family, and link function of the variable. This option can be used, however, to employ models that are not among those listed above.
to should be a character vector of length one indicating what model should be used during the imputation process. Valid choices for binary variables include
"cloglog", or quasilikelihoods
"qcloglog". For ordinal variables, valid choices include
"ocloglog". For count variables, valid choices include
"poisson". Currently the only valid option for gaussian variables is
"linear". To change the model for unordered-categorical variables, see the estimator slot in
what = "imputation_method"
Change the method for drawing imputed values from the conditional model specified for variable(s)
to should be a character vector of length one or of the same length as
y naming one of the following imputation methods:
"ppd" (posterior predictive distribution),
"pmm" (predictive mean matching),
"mean" (mean imputation),
"median" (median imputation),
"expectation" (conditional expectation imputation).
what = "size"
Optionally add additional rows for the purposes of prediction.
to should be a single integer. If
to is non-negative but less than the number of rows in the
missing_data.frame given by the
data argument, then
missing_data.frame is augmented with
to more rows, where all the additional observations are missing. If
to is greater than the number of rows in the
missing_data.framegiven by the
data argument, then the
missing_data.frame is extended to have
to rows, where the observations in the surplus rows are missing. If
to is negative, then any additional rows in the
missing_data.frame given by the
data argument are removed to restore it to its original size.
what = "transformation"
Specify a particular transformation to be applied to variable(s)
to should be a character vector of length one or of
the same length as
y indicating what transformation function to use. Valid choices are
"identity" for no transformation,
"standardize" for standardization (using twice the standard deviation of the observed values),
"log" for natural logarithm transformation,
"logshift" for a
log(y + a) transformation where
a is a small constant, or
"sqrt" for square-root transformation. Changing the transformation will also change the inverse transformation in the appropriate way. Any other value of
to will produce an informative error message indicating that the transformation and inverse transformation need to be changed manually.
Finally, if both
to are values then the former is recoded to the latter for all
occurances within the missing variable indicated by
If the data argument is not missing, then the method returns this argument with the
specified changes. If data is missing, then the method returns an object that inherits
missing_variable-class with the specified changes.
Ben Goodrich and Jonathan Kropko, for this version, based on earlier versions written by Yu-Sung Su, Masanao Yajima, Maria Grazia Pittau, Jennifer Hill, and Andrew Gelman.
1 2 3 4 5 6 7 8 9 10 11 12 13
# STEP 0: GET DATA data(nlsyV, package = "mi") # STEP 1: CONVERT IT TO A missing_data.frame mdf <- missing_data.frame(nlsyV) show(mdf) # STEP 2: CHANGE WHATEVER IS WRONG WITH IT mdf <- change(mdf, y = "momrace", what = "type", to = "un") mdf <- change(mdf, y = "income", what = "imputation_method", to = "pmm") mdf <- change(mdf, y = "binary", what = "family", to = binomial(link = "probit")) mdf <- change(mdf, y = 5, what = "transformation", to = "identity") show(mdf)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.