11

I am trying to fit generalized linear model for weibull family, but when I try it in R, it gives an error. I know that weibull does not fit in exponential family, but I have read some research articles about fitting GLM for weibull family. If anyone can help me with this, I really appreciate. It gives the following error.

> data(lung)
> glm(time ~ age+sex+ph.ecog+ wt.loss, family = weibull(link='log'), data = lung)
Error in glm(time ~ age + sex + ph.ecog + wt.loss, family = weibull(link = "log"),  : 
  could not find function "weibull"
kjetil b halvorsen
  • 63,378
  • 26
  • 142
  • 467
NiroshaR
  • 165
  • 1
  • 7

3 Answers3

5

Sorry i'm quite late with this.... but might help someone i believe :

gamlss package is what you should be looking for. It supports almost all the distributions( not just exponential family ones). It gives amazing flexibility on almost all the parameters of a distribution.

user3801801
  • 243
  • 2
  • 7
  • 3
    +1. `gamlss` supports the Weibull distribution via `WEI`, `WEI2` and `WEI3`, all 2-parameter though obviously different. Not sure if it supports censoring, though, which would be a key element of an AFT survival model. – Wayne Apr 26 '17 at 21:09
  • @Wayne gamlss definitely supports right censoring and left truncation also ....both also if wanted – user3801801 Apr 27 '17 at 11:31
3

The glm() function does not support the Weibull distribution in R unfortunately. You can try ?family to see which distributions are available. I would try using survreg() from the survival package instead.

Billywob
  • 203
  • 2
  • 6
  • yeah glm() do not support weibull. I am trying to use glm approach and AFT model using survreg, then compare the results of two methods. That is why I tried to figure it out to fit glm for weibull. Thank you for your comments. I appreciate it. – NiroshaR Jul 26 '16 at 04:26
1

I have used the brms package, which is Bayesian. It supports the Weibull, exponential, lognormal, Frechet, and other families and (left/right/interval) censoring so implements AFT models. It also includes random effects which are known in survival models as "frailty", and a host of other regression options like gam-style smoothers.

Since Bayesian approaches use MCMC sampling, it's slower than glm, gamlss, or survreg, but it's also a comprehensive regression solution, and being Bayesian has other advantages. (I love it's stanplot, which provides a host of illuminating diagnostic plots.)

Wayne
  • 19,981
  • 4
  • 50
  • 99