
## S3 method for class 'data.frame':
mi(object, info, n.imp = 3, n.iter = 30,
R.hat = 1.1, max.minutes = 20, rand.imp.method = "bootstrap",
run.past.convergence = FALSE,
seed = NA, check.coef.convergence = FALSE,
add.noise = noise.control())
## S3 method for class 'mi.preprocessed':
mi(object, n.imp = 3, n.iter = 30,
R.hat = 1.1, max.minutes = 20, rand.imp.method = "bootstrap",
run.past.convergence = FALSE,
seed = NA, check.coef.convergence = FALSE,
add.noise = noise.control())
## S3 method for class 'mi':
mi(object, n.iter = 30,
R.hat = 1.1, max.minutes = 20, rand.imp.method = "bootstrap",
run.past.convergence = FALSE, seed = NA)
mi
object that contains an incomplete data. mi
identifies NA
s as the missing data.mi.info
object.R.hat
statistic used as a convergence criterion. Default is 1.1.mi
implements only the boostrap
method.FALSE
. If the value is set to be TRUE
, mi
will run until the values of either n.iter
or max.minutes
are reached even if the imputation is converged.FALSE
. If the value is set to be TRUE
, mi
will check the convergence of the coefficients of imputation models.mi
via noise.control
.mi
, which stands for mi
.mi
has converged.mi
model have converged, return
NULL
if check.coef.convergence = FALSE
preprocess=TRUE
in the mi
processmi
if preprocess=TRUE
.imp[[m]]
is itself a list containg k variable lists of 3 objects:imp[[m]][[k]]@model
imp[[m]][[k]]@expected
imp[[m]][[k]]@random
mi.completed
, mi.data.frame
,
mi.continuous
, mi.binary
,
mi.count
, mi.categorical
,
mi.polr
, typecast
,
mi.info
, mi.preprocess
# simulate fake data
set.seed(100)
n <- 100
u1 <- rbinom(n, 1, .5)
v1 <- log(rnorm(n, 5, 1))
x1 <- u1*exp(v1)
u2 <- rbinom(n, 1, .5)
v2 <- log(rnorm(n, 5, 1))
x2 <- u2*exp(v2)
x3 <- rbinom(n, 1, prob=0.45)
x4 <- ordered(rep(seq(1, 5),100)[sample(1:n, n)])
x5 <- rep(letters[1:10],10)[sample(1:n, n)]
x6 <- trunc(runif(n, 1, 10))
x7 <- rnorm(n)
x8 <- factor(rep(seq(1,10),10)[sample(1:n, n)])
x9 <- runif(n, 0.1, .99)
x10 <- rpois(n, 4)
y <- x1 + x2 + x7 + x9 + rnorm(n)
fakedata <- cbind.data.frame(y, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10)
# randomly create missing values
dat <- mi:::.create.missing(fakedata, pct.mis=30)
# get information matrix of the data
inf <- mi.info(dat)
# update the variable type of a specific variable to mi.info
inf <- update(inf, "type", list(x10="count"))
# run the imputation without data transformation
#IMP <- mi(dat, info=inf, check.coef.convergence=TRUE,
# add.noise=noise.control(post.run.iter=10))
# run the imputation with data transformation
dat.transformed <- mi.preprocess(dat, inf)
#IMP <- mi(dat.transformed, n.iter=6, check.coef.convergence=TRUE,
# add.noise=noise.control(post.run.iter=6))
IMP <- mi(dat.transformed, n.iter=6, add.noise=FALSE)
# no noise
# IMP <- mi(dat, info=inf, n.iter=6, add.noise=FALSE) ## NOT RUN
# pick up where you left off
# IMP <- mi(IMP, n.iter = 6)
## this is the suggested (defautl) way of running mi
# IMP <- mi(dat, info=inf) ## NOT RUN
# convergence checking
converged(IMP, check = "data") ## You should get FALSE here because only n.iter is small
#converged(IMP, check = "coefs")
IMP.bugs1 <- bugs.mi(IMP, check = "data") ## BUGS object to look at the R hat statistics
#IMP.bugs2 <- bugs.mi(IMP, check = "coefs") ## BUGS object to look at the R hat statistics
plot(IMP.bugs1) ## visually check R.hat
# visually check the imputation
plot(IMP)
Run the code above in your browser using DataLab