Cumulative hazard curve fitting

443 views Asked by At

How technically it possible to prolong the cumulative hazard curves until day 80 if in my original data I have follow-up time until 50 day? The cumulative results estimates will remain the same just that both lines are the same until day 80.

Cumulative hazard plot

I used to create survival object object

surv = survfit(Surv(Tstart, Tstop, outcome==1)~T, data = data.long, ctype=1, id=id)

and then created a plot:

                 palette = c("#FF9E29", "#86AA00"),
                 risk.table = FALSE,
                 ylim=c(0,2),
                 xlim=c(0,70),
                 fun = "cumhaz")
1

There are 1 answers

0
danlooo On BEST ANSWER

You can transform the fit into a tibble for manual plotting using ggplot. By adding new rows at the maximal time point with the maximal value, geom_step will be extended as desired:

library(tidyverse)
library(survival)

fit <- survfit(Surv(time, status) ~ sex, data = lung)

max_time <- 3000

data <-
  tibble(
  cumhaz = fit$cumhaz,
  stratum = {
    fit$strata %>%
      as.numeric() %>%
      enframe() %>%
      mutate(vec = name %>% map2(value, ~ rep(.x, .y))) %>%
      pull(vec) %>%
      simplify()
  },
  time = fit$time
)

data %>%
  bind_rows(
    data %>% group_by(stratum) %>% summarise(cumhaz = max(cumhaz), time = max_time)
  ) %>%
  mutate(stratum = stratum %>% factor()) %>%
  ggplot(aes(time, cumhaz, color = stratum)) +
  geom_step() +
  scale_x_continuous(limits = c(0, max_time))

Created on 2022-04-14 by the reprex package (v2.0.0)