mice()可以处理crr()吗?细灰色模型 [英] can mice() handle crr()? Fine-Gray model

查看:171
本文介绍了mice()可以处理crr()吗?细灰色模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的疑问是,是否有可能在来自"crr()"的Fine-Gray的拟合模型上合并来自"mice()"的多个插补数据集,并且在统计上是正确的. ..

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...

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

推荐答案

要使其正常工作,需要做几件事.

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)

对于mice所需的crr模型没有vcov方法,但是, 我们可以使用model$var返回值访问协方差矩阵.

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

因此编写自己的vcov方法进行提取,并且还需要一个coef方法.

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

将模型传递给with.mids的方式也有一个错误:您的代码具有cov1=test1[,c( "x","sex")],但实际上您希望cov1使用估算的数据.由于cov1需要具有相关变量的矩阵,因此我不确定如何正确地将其写为表达式,但是您可以轻松地对函数进行硬编码.

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)
}


自此回答以来,mice内部结构已更改;现在,它使用broom包从拟合的crr模型中提取元素.因此,用于crr模型的tidyglance方法是必需的:

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))

请注意,这会在未定义df.residual时发出警告,因此假定为大样本.我对crr不熟悉,因此也许可以提取出更明智的值-然后将其添加到tidy方法中. (鼠标版本"3.6.0")

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’)

这篇关于mice()可以处理crr()吗?细灰色模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆