model = flexsurvreg(Surv(START,STOP,EVENT) ~ predictor1+predictor2,data= infection,dist="gamma")

p=ggflexsurvplot(model, xlab = "Time (Months)", censor = F, conf.int = T,
                 fun = "survival")

I am trying to do visual predictive checks such as KM curve overlaid with model prediction and prediction interval. I was able to achieve the plot by ggflexsurvplot. I am unable to interpret the plot.

1.Is KM for first event in that plot?. Is Model fit curve for all events in that plot? How can I interpret that plot? How can I do meaningful other plots /tables to interpret the effect of predictors on infection event time such as probability survival curve between predictors? 2.Covariate value is constant between interval, and it has full history of values from start of time. Can I use above gamma AFT model in flexsurv?. reason asking this question is: flexsurv says “ Likelihood is not valid in general however for other forms of dependence on covariates, e.g. accelerated failure time models”. 3.if not, can I use gamma PH model in flexsurv for above counting process(anderson gill) approach?

Note: This is repeated time to infection event meaning patients can have multiple events.Covariate is independent variable or predictor. This predictor is drug amount which vary daily(time varying).Dataset has start and end time for daily predictor value and event (0/1) variables.This is encoded in the above model.Hypothesis is to test whether drug amount causes infection events. For multiple events for a subject, time was encoded as start=0, end=1, then, 1-2,2-3,3-4.left truncation, right censored.(count process approach,anderson gill method).

  • $\begingroup$ Please edit the question to provide more information about the data, the hypothesis you are testing, and your model. Are there recurrent events, or can an individual have at most one event? If recurrent events, are you modeling all event times for an individual from a single time = 0, or are you resetting time = 0 for an individual at each event time? Why are you modeling this as AFT, and using a gamma survival model? Please provide that information by editing the question, as comments are easy to overlook and can be deleted. $\endgroup$
    – EdM
    Commented May 29, 2023 at 16:31
  • $\begingroup$ Also, please explain in more detail what you mean by "Covariate value is constant between interval, and it has full history of values from start of time." It would help if you could edit the question to show one or two examples of such data. $\endgroup$
    – EdM
    Commented May 29, 2023 at 16:39
  • $\begingroup$ answered your question in my Note edit above $\endgroup$
    – kamal
    Commented May 29, 2023 at 16:57

1 Answer 1


According to section 2 of its vignette, the assumptions of the flexsurv package include:

The individual survival times are also independent, so that flexsurv does not currently support shared frailty, clustered or random effects models.

That poses two problems for your application. One is that, even without time-varying covariates, you would have to do extra work to deal with the lack of independence among observations on the same individual. That alone could be dealt with fairly easily, for example by modeling on repeated bootstrap samples where the bootstraps were done per individual instead of per observation.

The second problem posed by the independence problem is more difficult. Unlike a proportional hazards model, an accelerated failure time (AFT) model requires the entire history of a covariate. This is simply explained in Section 2 of a vignette of the eha package. The independence assumption made by flexsurv is why you find the statement you quote from Section 3.1 of the flexsurv vignette that the necessary assumptions are:

not valid in general however for other forms of dependence on covariates, e.g. accelerated failure time models.

The aftreg() function of the eha package does allow for an id argument to keep track of data by individual. That allows reconstruction of the entire covariate history for an individual so that you can fit an AFT model properly. That package does not, however, allow for gamma survival models.

Alternatively, if it would make sense to reset time = 0 at each event time for an individual (which can be done in the context of an Andersen-Gill model), then you could fit a gamma model with flexsurvreg() and then deal with the lack of independence via bootstrapping by individual.

Think carefully about why you are modeling in the particular way you have chosen so far. You might be able to accomplish what you want in other ways, for example via a proportional hazards model instead.

The question about ggsurvplot() from the survminer package is perhaps too software-specific to be on-topic on this site. In general, if you have recurrent events you want a plot of cumulative incidence rather than a usual Kaplan-Meier plot of survival probability over time. I'm not sure how that particular package handled your data.

  • $\begingroup$ thank you very much. I have entire history of covariate. I think i can go with eha with id option eventhough it does not have gamma-AFT.Flexsurv does not have ID option. ID option also accounts for within subject correlation. I will screen for available distribution in eha package and select lowest AIC from both PH and AFT. For plot I am thinking like mean cumulative events at each time point. I am also doing CoxPh and comparing with parametric models. $\endgroup$
    – kamal
    Commented May 29, 2023 at 19:27

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.