03change: Make Changes to Discretionary Characteristics of Missing...

03changeR Documentation

Make Changes to Discretionary Characteristics of Missing Variables

Description

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 missing_variable is modeled.

Usage

change(data, y, to, what, ...)
change_family(data, y, to, ...)
change_imputation_method(data, y, to, ...)
change_link(data, y, to, ...)
change_model(data, y, to, ...)
change_size(data, y, to, ...)
change_transformation(data, y, to, ...)
change_type(data, y, to, ...)

Arguments

data

A missing_data.frame (typically) but can be missing for all but the change function

y

A character vector (typically) naming one or more missing_variables within the missing_data.frame specified by the data argument. Alternatively, y can be the name of a class that inherits from missing_variable, in which case all missing_variables of that class within data will be changed. Can also be an vector of integers or a logical vector indicating which missing_variables to change.

what

Typically a character string naming what is to be changed, such as "family", "imputation_method", "size", "transformation", "type", "link", or "model". Alternatively, it can be a scalar value, in which case all occurances of that value for the variable indicated by y will be changed to the value indicated by to

to

Typically a character string naming what y should be changed to, such as one of the admissible families, imputation methods, transformations, or types. If missing, then possible choices for the to argument will be helpfully printed on the screen. If what is a number, then to should be the number (or NA) that the value designated by what will be recoded to. See the Details section for more information.

...

Other arguments, not currently utilized

Details

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 change before mi is run.

In general, most users will only use the change command. change will then call change_family, change_imputation_method, change_link, change_model, change_size, change_transformation, or 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) y. 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 "unordered-categorical", "ordered-categorical", "binary", "interval", "continuous", "count", and "irrelevant".

what = "family"

Change the distribution family for variable(s) y. 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 ordered-categorical-class or 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) y. 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 fit_model and mi-methods yet.

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 "logit", "probit" "cauchit", "cloglog", or quasilikelihoods "qlogit", "qprobit", "qcauchit", "qcloglog". For ordinal variables, valid choices include "ologit", "oprobit", "ocauchit", and "ocloglog". For count variables, valid choices include "qpoisson" and "poisson". Currently the only valid option for gaussian variables is "linear". To change the model for unordered-categorical variables, see the estimator slot in missing_variable.

what = "imputation_method"

Change the method for drawing imputed values from the conditional model specified for variable(s) y. 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) y. 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.

what = a value

Finally, if both what and to are values then the former is recoded to the latter for all occurances within the missing variable indicated by y.

Value

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 from the missing_variable-class with the specified changes.

Author(s)

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.

See Also

missing_variable, missing_data.frame

Examples

# 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)

mi documentation built on June 7, 2022, 1:04 a.m.