7
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ Thanks, I reworded/clarified the question to bring it on topic. $\endgroup$ – george Apr 7 '16 at 12:54
  • $\begingroup$ 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. $\endgroup$ – Wayne Dec 20 '16 at 14:26
2
$\begingroup$

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

Just call the flexsurvreg function instead of survreg.

$\endgroup$
2
$\begingroup$

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 :)

$\endgroup$
1
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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