View source: R/mice.impute.rlm.R
mice.impute.rlm | R Documentation |
These functions impute from linear models using the functions
stats::lm
, MASS::rlm
or MASS::lqs
. The method mice.impute.lm_fun
allows the definition of a general linear regression fitting function for
which the methods predict
and residuals
are defined.
Parameters of the model are estimated by Bayesian bootstrap. Predicted values are computed and residuals are randomly drawn from the empirical distribution of residuals of observed data.
mice.impute.lm(y, ry, x, wy=NULL, lm_args=NULL, trafo=NULL, antitrafo=NULL, ...)
mice.impute.rlm(y, ry, x, wy=NULL, lm_args=NULL, trafo=NULL, antitrafo=NULL, ...)
mice.impute.lqs(y, ry, x, wy=NULL, lm_args=NULL, trafo=NULL, antitrafo=NULL, ...)
mice.impute.lm_fun(y, ry, x, wy=NULL, lm_args=NULL, lm_fun="lm", trafo=NULL,
antitrafo=NULL, ...)
y |
Incomplete data vector of length |
ry |
Vector of missing data pattern ( |
x |
Matrix ( |
wy |
Vector of logicals indicating which entries should be imputed |
lm_args |
List of arguments for |
lm_fun |
Linear regression fitting function, e.g. |
trafo |
Optional function for transforming the outcome values |
antitrafo |
Optional function which is the inverse function of |
... |
Further arguments to be passed |
A vector of length nmis=sum(!ry)
with imputed values.
## Not run:
#############################################################################
# EXAMPLE 1: Some toy example illustrating the methods
#############################################################################
library(MASS)
library(mice)
#-- simulate data
set.seed(98)
N <- 1000
x <- stats::rnorm(N)
z <- 0.5*x + stats::rnorm(N, sd=.7)
y <- stats::rnorm(N, mean=.3*x - .2*z, sd=1 )
dat <- data.frame(x,z,y)
dat[ seq(1,N,3), c("x","y") ] <- NA
dat[ seq(1,N,4), "z" ] <- NA
#-- define imputation methods
imp <- mice::mice(dat, maxit=0)
method <- imp$method
method["x"] <- "rlm"
method["z"] <- "lm"
method["y"] <- "lqs"
#-- impute data
imp <- mice::mice(dat, method=method)
summary(imp)
#--- example using transformations
dat1$x <- exp(dat1$x)
dat1$z <- stats::plogis(dat1$z)
trafo <- list(x=log, z=stats::qlogis)
antitrafo <- list(x=exp, z=stats::plogis)
#- impute with transformations
imp2 <- mice::mice(dat1, method=method, m=1, maxit=3, trafo=trafo, antitrafo=antitrafo)
print(imp2)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.