# 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, 10)
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
## this is for test only
IMP <- mi(dat, info=inf, n.iter=6, post.run=FALSE)
# no prior
# IMP <- mi(dat, info=inf, n.iter=6, add.priors=FALSE)
# pick up where you left off
# IMP <- mi(IMP) ## NOT RUN
## this is the suggested (defautl) way of running mi, NOT RUN
# IMP <- mi(dat, info=inf)
# convergence checking
converged(IMP) ## You should get FALSE here because only n.iter is small
bugs.mi(IMP) ## BUGS object to look at the R hat statistics
# visually check the imputation
plot(IMP)
Run the code above in your browser using DataLab