7
$\begingroup$

the generalized gamma distribution is a generalization of the two-parameter gamma distribution: https://en.wikipedia.org/wiki/Generalized_gamma_distribution

However I cannot find an implementation in R (or python) that let's me use this in a GLM framework, so something like glm(y ~ x, family(GenGamma)).

I could only find a distribution definition in the flexsurv package, but only for a survival usage.

Is there a way to use the generalized gamma in a GLM setting?

UPDATE:

method 1. suggested by @Glen_b works quite well:

library(flexsurv)
df <- data.frame(y = runif(100, 1, 10), x1 = rnorm(100))
flexsurvreg(Surv(y) ~ x1, data = df, dist = "gengamma")
$\endgroup$
1
  • 4
    $\begingroup$ This might be impossible with standard techniques. GLMs are usually fitted assuming that the distribution comes from the exponential family. The gamma distribution is exponential family, but its generalization is not. You will have to compute and optimize its likelihood yourself. Beware the folk theorem of statistical computing. If all you're interested in is trying to find the correct functional form for your model, you might be better off fitting each kind and comparing the results. $\endgroup$ Oct 11, 2016 at 11:07

1 Answer 1

7
$\begingroup$

There are several reasonably clear options.

  1. You can use the survival model. Treat the response values as all-uncensored survival times. I've used this strategy to fit Weibull models for example; it often works quite well.

    There's an example here that shows doing it with a Weibull model for non-survival data. [There's a second example here of using it to simply fit a Weibull distribution in a case where the usual fitdistr approach was having trouble.]

    Those two examples should be sufficient to convey the general idea, and apply it to the generalized gamma.

  2. If you know the "power" parameter ($p$ in the Wikipedia link) you can transform the data to a Gamma and use GLM.

  3. If $p$ is unknown, you can use the fact that conditional on $p$ you can fit a GLM (and then ML estimation of the scale parameter for that, such as via the relevant function in MASS - which is using a similar idea) to get a profile likelihood for $p$, to obtain an overall MLE for $p$ and the gamma parameters.

  4. Alternatively you can try to use direct optimization of the likelihood.

$\endgroup$
6
  • 1
    $\begingroup$ I tried method 1 you suggested and it seems to work. Thank you. $\endgroup$
    – spore234
    Oct 11, 2016 at 13:07
  • $\begingroup$ Glad it helped. It's interesting to me how often even quite experienced statisticians express surprise / astonishment at what seems to me to be a very ordinary notion: using a function that fits a distribution to a set of observations that may or may not be censored to fit observations where none are censored. The survival modelling code doesn't care whether they're times or insurance claims or concentrations of a chemical in blood samples or bank profits. You just have to read the information to figure out what parameterization the models use (or maybe to generate some data and figure it out) $\endgroup$
    – Glen_b
    Oct 11, 2016 at 23:03
  • $\begingroup$ ... so sometimes you need to reparameterize after the fit and maybe use a Taylor approximation to get an estimate of the standard error of a parameter under a reparameterized version of the fitted model. $\endgroup$
    – Glen_b
    Oct 11, 2016 at 23:05
  • $\begingroup$ a problem arised when predicting. flexsurv has no predict function. When I matrix multiply the new data with the parameter estimates I am not on the scale of the response variable. I have no idea what link function is used here. How can I get something like type = "response" ? $\endgroup$
    – spore234
    Oct 12, 2016 at 11:02
  • $\begingroup$ My previous two comments relate to this issue. Note that the help on flexsurvreg mentions that it's an AFT model. The Wikipedia page for the distribution mentions the parameterization, which is the same as that described in the help on the generalized gamma functions in the package (see ?GenGamma). The paper by Cox et al (2007) in the references gives lots of detail and is probably what you need. This pdf gives some details about how AFT survival models work including the generalized gamma. $\endgroup$
    – Glen_b
    Oct 12, 2016 at 11:45

Your Answer

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

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