can mice() handle crr()? Fine-Gray model

青春壹個敷衍的年華 提交于 2019-12-01 13:32:05

问题


My doubt is if it is possible to pool multiple imputation data set, from "mice()", on a fit model of Fine-Gray from "crr()", and if it is statistically correct...

example

library(survival)
library(mice)
library(cmprsk)

test1 <- as.data.frame(list(time=c(4,3,1,1,2,2,3,5,2,4,5,1, 4,3,1,1,2,2,3,5,2,4,5,1), 
                            status=c(1,1,1,0,2,2,0,0,1,1,2,0, 1,1,1,0,2,2,0,0,1,1,2,0),
                            x=c(0,2,1,1,NA,NA,0,1,1,2,0,1, 0,2,1,1,NA,NA,0,1,1,2,0,1),
                            sex=c(0,0,0,NA,1,1,1,1,NA,1,0,0, 0,0,0,NA,1,1,1,1,NA,1,0,0)))

dat <- mice(test1,m=10, seed=1982)

#Cox regression: cause 1

models.cox1 <- with(dat,coxph(Surv(time, status==1) ~ x +sex ))                 

summary(pool(models.cox1))

#Cox regression: cause 1 or 2

models.cox <- with(dat,coxph(Surv(time, status==1 | status==2) ~ x +sex ))                 
models.cox
summary(pool(models.cox))


#### crr()

#Fine-Gray model

models.FG<- with(dat,crr(ftime=time, fstatus=status,  cov1=test1[,c( "x","sex")], failcode=1, cencode=0, variance=TRUE))                 

summary(pool(models.FG))

#Error in pool(models.FG) : Object has no vcov() method.

models.FG

回答1:


There are a couple of things that need to be done to get this to work.

Your initial data and imputation.

library(survival)
library(mice)
library(cmprsk)

test1 <- as.data.frame(list(time=c(4,3,1,1,2,2,3,5,2,4,5,1, 4,3,1,1,2,2,3,5,2,4,5,1), 
                            status=c(1,1,1,0,2,2,0,0,1,1,2,0, 1,1,1,0,2,2,0,0,1,1,2,0),
                            x=c(0,2,1,1,NA,NA,0,1,1,2,0,1, 0,2,1,1,NA,NA,0,1,1,2,0,1),
                            sex=c(0,0,0,NA,1,1,1,1,NA,1,0,0, 0,0,0,NA,1,1,1,1,NA,1,0,0)))

dat <- mice(test1,m=10, print=FALSE)

There is no vcov method for crr models which mice requires, however, we can access the covariance matrix using the model$var returned value.

So write own vcov method to extract, and also need a coef method.

vcov.crr <- function(object, ...) object$var # or getS3method('vcov','coxph')
coef.crr <- function(object, ...) object$coef

There is also an error in how the model is passed to with.mids: your code has cov1=test1[,c( "x","sex")], but really you want cov1 to use the imputed data. I am not sure how to correctly write this as an expression due to the cov1 requiring a matrix with relevant variables, but you can easily hard code a function.

# This function comes from mice:::with.mids
Andreus_with <- 
function (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]] <- crr(ftime=data.i[,'time'], fstatus=data.i[,'status'],  
                         cov1=data.i[,c( "x","sex")], 
                         failcode=1, cencode=0, variance=TRUE)
    }
    object <- list(call = call, call1 = data$call, nmis = data$nmis, 
        analyses = analyses)
    oldClass(object) <- c("mira", "matrix")
    return(object)
}

EDIT:

The mice internals have changed since this answer; it now uses the broom package to extract elements from the fitted crr model. So tidy and glance methods for crr models are required:

tidy.crr <- function(x, ...) {
  co = coef(x)
  data.frame(term = names(co), 
             estimate = unname(co), 
             std.error=sqrt(diag(x$var)), 
             stringsAsFactors = FALSE)
}

glance.crr <- function(x, ...){ }

The above code then allows the data to be pooled.

models.FG <- Andreus_with(dat)                 
summary(pool(models.FG))

Note that this gives warnings over df.residual not being defined, and so large samples are assumed. I'm not familiar with crr so a more sensible value can perhaps be extracted -- this would then be added to the tidy method. (mice version ‘3.6.0’)



来源:https://stackoverflow.com/questions/41794649/can-mice-handle-crr-fine-gray-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!