03change {mi} | R 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 |
y |
A character vector (typically) naming one or more |
what |
Typically a character string naming what is to be changed, such
as |
to |
Typically a character string naming what |
... |
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 themissing_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 classfamily
or a list where each element is of classfamily
. If a variable is ofbinary-class
, then the family must bebinomial
(the default) or possiblyquasibinomial
. If a variable is ofordered-categorical-class
orunordered-categorical-class
, use themultinomial
family. If a variable is ofcount-class
, then the family must bequasipoisson
(the default) orpoisson
. If a variable is continuous, there are more choices for its family, butgaussian
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. Seefamily
for details; however, not all of these link functions have appropriatefit_model
andmi-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 inmissing_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 asy
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. Ifto
is non-negative but less than the number of rows in themissing_data.frame
given by thedata
argument, thenmissing_data.frame
is augmented withto
more rows, where all the additional observations are missing. Ifto
is greater than the number of rows in themissing_data.frame
given by thedata
argument, then themissing_data.frame
is extended to haveto
rows, where the observations in the surplus rows are missing. Ifto
is negative, then any additional rows in themissing_data.frame
given by thedata
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 asy
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 alog(y + a)
transformation wherea
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 ofto
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
andto
are values then the former is recoded to the latter for all occurances within the missing variable indicated byy
.
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)