8

I am trying to run a survival model using the Weibull approach, but the wrinkle is that I have time-varying covariates. I am using the survival package in R. My call is:

output <- survreg(Surv(start, stop, fail) ~ gdppc + [...] + cluster(name), data = mydata, dist="weibull")

which yields the following error:

Error in survreg(Surv(start, stop, fail) ~ gdppclag + : 
  Invalid survival type

The coxph procedure works fine, but I want to use the weibull.

My first question is: can the Weibull approach account for time-variant covariates? I've looked around at some texts, and I see that the Cox PH approach can be extended to time-variant covariates. It's less clear if the Weibull approach can do it.

Second, if indeed the Weibull can work, what are the packages in R that can process it?

george
  • 81
  • 1
  • 3
  • Thanks, I reworded/clarified the question to bring it on topic. – george Apr 07 '16 at 12:54
  • I wouldn't be hasty that the coxph worked or that the survreg cannot handle it. The error message implies that your fail code has strange values. Could you elaborate on how start, stop, and fail are coded? Also, have you read the survival vignette on time-varying covariates? The survival vignettes are very good. – Wayne Dec 20 '16 at 14:26

3 Answers3

4

The flexurv package can do this: https://cran.r-project.org/web/packages/flexsurv/index.html

Just call the flexsurvreg function instead of survreg.

3

You can do it with Survival package by the following :

Srv <- Surv(start, stop, fail, type="interval" )

and then you can use Srv in your model as :

output <- survreg(Surv(start, stop, fail) ~ gdppc + [...] + cluster(name), data = mydata, dist="weibull")

Hope this can help :)

Abdal
  • 125
  • 1
  • 8
  • This answer is misleading or incorrect, at several levels. First, the `Srv` object does not appear at all in the call to `survreg`. Second, if you do try to use that form of `Surv()` object in a call to `survreg` with data formatted in the usual way for time-dependent covariates, it fails with Survival_3.2-7. Third, even if it didn't fail it would give an incorrect answer, as the proper handling of time-dependent covariates is _left-truncated, right censored_, not interval censored. Interval censored means that an event happens somewhere _between_ the endpoints. – EdM Jul 30 '21 at 18:25
3

This can also be achieved with the aftreg command from the eha package. To obtain the same parametrisation normally used by the survreg command from the survival package, and also by the flexsurvreg command from the flexsurv package, the param option must be set to "LifeExp", as explained in the package's documentation. An adaptation of your code would therefore be as follows:

output <- aftreg(Surv(start, stop, fail) ~ gdppc + [...] + cluster(name), data = mydata, dist="weibull", param="lifeExp")

One advantage of the eha::aftreg command is that it is compatible with stargazer and thus its output can be easily exported to LaTeX format.

Lino Ferreira
  • 283
  • 2
  • 9