# NOT RUN {
N = 100
set.seed(123)
dat <- data.frame(y=runif(N), x1=runif(N), x2=runif(N), z=runif(N))
true = qgcomp.noboot(f=y ~ z + x1 + x2, expnms = c('x1', 'x2'),
data=dat, q=2, family=gaussian())
mdat <- dat
mdat$x1 = ifelse(mdat$x1>0.5, mdat$x1, NA)
mdat$x2 = ifelse(mdat$x2>0.75, mdat$x2, NA)
cc <- qgcomp.noboot(f=y ~ z + x1 + x2, expnms = c('x1', 'x2'),
data=mdat[complete.cases(mdat),], q=2, family=gaussian())
# }
# NOT RUN {
# note the following example imputes from the wrong parametric model and is expected to be biased
# as a result (but it demonstrates how to use qgcomp and mice together)
library("mice")
library("survival")
impdat = mice(data = mdat,
method = c("", "leftcenslognorm", "leftcenslognorm", ""),
lod=c(NA, 0.5, 0.75, NA), debug=FALSE)
qc.fit.imp <- list(
call = call("qgcomp.noboot(y~., expnms = c('x1', 'x2'), family=gaussian())"),
call1 = impdat$call,
nmis = impdat$nmis,
analyses = lapply(1:5, function(x) qgcomp.noboot(y~., expnms = c("x1", "x2"),
data=complete(impdat, x), family=gaussian(), bayes=TRUE))
)
obj = pool(as.mira(qc.fit.imp))
# true values
true
# complete case analysis
cc
# MI based analysis
summary(obj)
# }
Run the code above in your browser using DataLab