[R] MICE for Cox model

Inman, Brant A. M.D. Inman.Brant at mayo.edu
Thu May 17 06:19:04 CEST 2007


I have a dataset that has 168 subjects and 12 variables.  Some of the
variables have missing data and I want to use the multiple imputation
capabilities of the "mice" package to address the missing data. Given
that mice only supports linear models and generalized linear models (via
the lm.mids and glm.mids functions) and that I need to fit Cox models, I
followed the previous suggestion of John Fox and have created my own
function "cox.mids" to use coxph to fit models to the imputed datasets.


The function I created is:


cox.mids <- function (formula, data, ...)
    call <- match.call()
    if (!is.mids(data)) 
        stop("The data must have class mids")
    analyses <- as.list(1:data$m)
    for (i in 1:data$m) {
        data.i <- complete(data, i)
        analyses[[i]] <- coxph(formula, data = data.i, ...)
    object <- list(call = call, call1 = data$call, nmis = data$nmis, 
        analyses = analyses)
    oldClass(object) <- c("mira", "coxph")


The problem that I encounter occurs when I try to use the "pool"
function to pool the fitted models into one general model. Here is some
code that reproduces the error using the pbc dataset.


d <- pbc[,c('time','status','age','sex','hepmeg','platelet', 'trt',
d[d==-9] <- NA 
d[,c(4,5,7)] <- lapply(d[,c(4,5,7)], FUN=as.factor)

imp <- mice(d, m=10, maxit=10, diagnostics=T, seed=500, 
	defaultImputationMethod=c('norm', 'logreg', 'polyreg'))

fit <- cox.mids(Surv(time,status) ~ age + sex + hepmeg + platelet + trt
+ 	trig, imp)



I have looked at the "pool" function but cannot figure out what I have
done wrong.  Would really appreciate any help with this.


Brant Inman
Mayo Clinic

More information about the R-help mailing list