Have hade major issues doing a fine-gray Crr() analysis with imputed data (mids-type data, imputed using mice-packge). Problem seem to be the Cov1-command, as i cannot get it to draw data from the mids-data. I have tried for a couple of hours searching for a solution, including using different types of packages and methods without success. Help would be most appreciated!
There is an old example with a different set of problem here where there was a vcov-related problem. As the package is now updated this is no longer the problem. Ill use the same code for exemplary purposes.
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))
#8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
#model draws from orignial dataset, thus missing values, changing to mids-dataset
models.FG<- with(dat,crr(ftime=time, fstatus=status, cov1=dat[,c( "x","sex")], failcode=1, cencode=0, variance=TRUE))
#Error in dat[, c("x", "sex")] : incorrect number of dimensions
#problem persists after changing to specific directory
models.FG<- with(dat,crr(ftime=time, fstatus=status, cov1=dat$imp[,c( "x","sex")], failcode=1, cencode=0, variance=TRUE))
#Error in dat$imp[, c("x", "sex")] : incorrect number of dimensions
# coding my own model.matrix
previous_na_action <- options('na.action')
options(na.action='na.pass')
cov1 <- model.matrix( ~ factor(x)
+ factor(sex),
data = test1)[, -1]
options(na.action=previous_na_action$na.action)
models.FG<- with(dat,crr(ftime=time, fstatus=status, cov1=cov1, failcode=1, cencode=0, variance=TRUE))
#8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
# Same problem, i the same dimentional problems persist i u try to use "data=dat$imp"
# use listed imputed data as source?
longdat <- complete(dat, action='long', inc=TRUE)
previous_na_action <- options('na.action')
options(na.action='na.pass')
cov1 <- model.matrix( ~ factor(x)
+ factor(sex),
data = longdat)[, -1]
options(na.action=previous_na_action$na.action)
models.FG<- with(dat,crr(ftime=time, fstatus=status, cov1=cov1, failcode=1, cencode=0, variance=TRUE))
#8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
8 cases omitted due to missing values
# still same problem
models.FG
Any ideas how i cant get the With() to index the coviariates correctly? Any other package who could handle CRR-analysis on mids-object? as theoretically i suppose i could convert the mids to usual data -> do analysis separately -> converge the datasets i tried to do that with as.mira-command but could not get that to work either.