Dear community,
Momentarily I am completely stuck at multiple imputation. I have used SMCFCS to be able to impute with cox proportional hazards. When I wanted to convert SMCFCS object to a MICE object and check my results with convergence plots and density plots, I only received errors which I could not solve. Does anyone know where this might come from?
I have created the reprex below. If more information is needed, please let me know. Thank you in advance for your help.
#Libraries
library(smcfcs)
library(rms)
library(mice)
library(miceadds)
library(survival)
#Test
data <- lung
data <- data[,c(1:3,5,6)]
data$sex <- as.factor(data$sex)
data$ph.ecog[data$ph.ecog == 3] <- 2
data$ph.ecog <- as.factor(data$ph.ecog)
data$time <- as.numeric(data$time)
# Use mice for some convenient functions creating method list and predictor matrix using the dataset at hand
ini <- mice(data,m=1,maxit=0)
method <- ini$method
method[method=="pmm"] <- "norm" # replace pmm with norm for smcfcs
method[method=="polyreg"] <- "mlogit" # replace polyreg with mlogit for smcfcs
#Predictormatrix
predMatrix <- ini$predictorMatrix
predMatrix[c("time","status","sex"),] <- 0 #are complete, so do not need imputing
predMatrix[,c("time","status")] <- 0
#Imputation
db.imputed <- smcfcs(
data,
smtype= "coxph",
smformula = "Surv(time, status) ~ sex + ph.ecog",
method=method,
predictorMatrix = predMatrix,
m = 2, #test: 2
numit = 10, #test: 10
rjlimit = 1000,
noisy = FALSE,
errorProneMatrix = NULL)
warnings()
#Checks
db.mice <- miceadds::datlist2mids( db.imputed$impDatasets ) #convert smcfcs datalist to mids object
#Convergence plot with actual values instead of beta on Y-axis (traceplot)
plot(db.mice) #Error
densityplot(db.mice) #Error