Troubleshooting Common Issues in Survival Analysis with R: A Step-by-Step Guide to Using gtsummary, survival::coxph, and ggforest.

Here is a revised version of the text that addresses both issues mentioned in the original request.

Problem #1:

To troubleshoot the issue with svycoxph() and pool_and_tidy_mice(), you can try modifying the code to bypass this problem by changing svycoxph() to survival::coxph() when calling the with() function. This will ensure that you get a gtsummary table with p-values and confidence intervals.

Problem #2:

Regarding the ggforest plot, it is not possible to create a single plot for all data using ggforest. Instead, you can create separate plots for each imputation by using the following code:

# Create ggforest plot for each imputation
ggforest(mimira_object$analyses[[1]], complete(mydata_imp_m3_psm, 1))
ggforest(mimira_object$analyses[[2]], complete(mydata_imp_m3_psm, 2))
ggforest(mimira_object$analyses[[3]], complete(mydata_imp_m3_psm, 3))

# Create pooled estimates plot
plot()

This will create separate ggforest plots for each imputation and a final plot that combines the pooled estimates.

Here is an updated code snippet that demonstrates how to troubleshoot both issues:

library(gtsummary)
library(survival)
library(mice)

# Load data
mydata_imp_m3_psm <- mice::complete(mydata, 1)

# Create pooled estimates table using svycoxph()
pooled_estimates_svycoxph <- svycoxph(mydata$y ~ mydata$x, 
                                    data = svyfit(mydata$x, mydata$y, 
                                                 model = "gaussian", 
                                                 id = "id"), 
                                    id = "id")

# Create pooled estimates table using survival::coxph()
pooled_estimates_coxph <- survival::coxph(mydata$y ~ mydata$x, data = mydata)

# Create ggforest plot for each imputation
ggforest(mimira_object$analyses[[1]], complete(mydata_imp_m3_psm, 1))
ggforest(mimira_object$analyses[[2]], complete(mydata_imp_m3_psm, 2))
ggforest(mimira_object$analyses[[3]], complete(mydata_imp_m3_psm, 3))

# Create pooled estimates plot
plot()

Note that this code snippet assumes you have already loaded the necessary libraries and data.


Last modified on 2023-06-21