0
$\begingroup$

I am trying to fit a discrete-time survival analysis using R. My overall goal is to check if the variable pain impacts smoking. Every time I include the variable as.factor(time_to_smoking) the model does not converge, even if I remove all other covariates. If I don't include it, the model converges.

I need help finding the model that would most accurately represent the plot.

merged_data_surv <- merged_data_any %>%
  mutate(
    time_to_smoking = case_when(
      smoking_any == 1 & smoking_w2 == 1 ~ 1,
      smoking_any == 1 & smoking_w3 == 1 ~ 2,
      smoking_any == 1 & smoking_w4 == 1 ~ 3,
      smoking_any == 1 & smoking_w5 == 1 ~ 4,
      smoking_any == 1 & smoking_w6 == 1 ~ 5,
      TRUE ~ 6
    )
  ) %>%
  filter(
    !is.na(R01R_A_SEX_IMP),
    !is.na(R01R_A_AGECAT7_IMP),
    !is.na(R01R_A_AM0018),
    !is.na(R01R_A_RACECAT3_IMP),
    !is.na(R01R_A_HISP_IMP)
  ) %>%
  left_join(da36498.6111 %>% select(PERSONID, R06_A_A01WGT), by = "PERSONID")


PATH_design_surv <- svrepdesign(
  data = merged_data_surv,
  weights = ~R06_A_A01WGT.x,
  repweights = "R06_A_A01WGT[1-9]+",
  type = "Fay",
  rho = 0.3,
  scale = 1,
  rscales = 1
)

cox_model <- svyglm(smoking_any ~ as.factor(time_to_smoking) + pain + R01R_A_SEX_IMP + 
                      R01R_A_AGECAT7_IMP + R01R_A_AM0018 + R01R_A_RACECAT3_IMP + 
                      R01R_A_HISP_IMP, design = PATH_design_surv, 
                    family = quasibinomial(link = "logit"))

cox_summary <- summary(cox_model)


merged_data_surv$pain_cat <- factor(merged_data_surv$pain, levels = c(0, 1), labels = c("No or Low Pain", "Moderate or Severe Pain"))
# Plot the 1-KM curve using ggsurvplot with custom modifications
ggsurvplot(
    survfit(Surv(time_to_smoking, smoking_any) ~ pain_cat, data = merged_data_surv),
    data = merged_data_surv,
    conf.int = TRUE,
    legend.labs = c("No or Low Pain", "Moderate or Severe Pain"),
    risk.table = "nrisk_cumevents",
    legend = "none",
    xlab = "Waves",
    ylab = "Cumulative Incidence of Daily Smoking (%)",
    xlim = c(1, 6),
    ylim = c(0,8),
    break.time.by = 1,
    font.family = "Aptos",
    palette = c("#705fec", "#f87d5c"),
    ggtheme = theme_bw(base_family = "Aptos") +
      theme(plot.title = element_text(family = "Aptos", size = 14, face = "bold"),
            axis.title = element_text(family = "Aptos", size = 12, face = "bold"),
            axis.title.y = element_text(margin = margin(t = 0, r = 20, b = 0, l = 0)),
            axis.text = element_text(family = "Aptos", size = 10.3, face = "bold"),
            legend.text = element_text(family = "Aptos", size = 12, face = "bold"),
            panel.grid.major = element_blank(),  # Remove all major grid lines
            panel.grid.minor = element_blank(),  # Remove all minor grid lines
            panel.border = element_blank(),  # Remove all borders
            axis.line = element_line(colour = "black"),  # Add axis lines on the left and bottom
            legend.title = element_blank()),
    tables.theme = theme(axis.title.y = element_blank(),
                         plot.title = element_text(family = "Aptos", size = 12, face = "bold"),
                         axis.title.x = element_blank(),
                         axis.text.x = element_blank(),
                         panel.border = element_blank(),
                         axis.line = element_blank(),
                         axis.text.y = element_text(family = "Aptos", face = "bold", size = 12)),
    surv.plot.height = 0.75,  # Adjust the height of the survival plot
    risk.table.height = 0.25,  # Adjust the height of the risk table
    risk.table.title ="No. at risk (no. of events)",
    fun = function(x) (1 - x) * 100  # Transform the survival probability to cumulative incidence
    )
$\endgroup$
4
  • $\begingroup$ Cox PH is not a discrete time survival model? Perhaps try fitting a logit hazard model or similar a la Singer, J. D., & Willett, J. B. (1993). It’s about time: Using discrete-time survival analysis to study duration and the timing of events. Journal of Educational and Behavioral Statistics, 18(2), 155–195. $\endgroup$
    – Alexis
    Commented May 5 at 23:37
  • 1
    $\begingroup$ As of my understanding, I think Cox PH is applicable only to continuous time. Thanks for the reference, will check it. $\endgroup$ Commented May 6 at 15:59
  • $\begingroup$ Discrete time survival analysis is EXACTLY what I need. Not sure if you read the post $\endgroup$ Commented May 6 at 17:44
  • $\begingroup$ No problem!! ;) $\endgroup$ Commented May 6 at 18:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.