16
$\begingroup$

Simple question: How to specify a lognormal distribution in the GLM family argument in R? I could not find how this can be achieved. Why is lognormal (or exponential) not an option in the family argument?

Somewhere in the R-Archives I read that one simply has to use the log-link for the family set to gaussian in the GLM, in order to specify a lognormal. However, this is nonsense because this will fit a non-linear regression and R starts asking for starting values.

Is anybody aware how to set a lognormal (or exponential) distribution for a GLM?

$\endgroup$
  • 1
    $\begingroup$ This should be on SO with an [r] tag. $\endgroup$ – DWin Jan 21 '12 at 15:40
  • 4
    $\begingroup$ @DWin - I disagree for once - I often vote to migrate Qs to SO myself, but this question has significant statistical content. $\endgroup$ – onestop Jan 21 '12 at 16:23
8
$\begingroup$

The gamlss package allows you to fit generalized additive models with both lognormal and exponential distributions, and a bunch of others, with some variety in link functions and using, if you wish, semi- or non-parametric models based on penalized splines. It's got some papers published on the algorithms used and documentation and examples linked to the site I've linked to.

$\endgroup$
10
$\begingroup$

Regarding fitting the exponential model with glm: When using the glm function with family=Gamma one needs to also use the supporting facilities of summary.glm in order to fix the dispersion parameter to 1:

?summary.glm
fit <- glm(formula =..., family = Gamma)
summary(fit,dispersion=1) 

And as I was going to point out but jbowman beat me to it, the "gamlss" package(s) provides for log-normal fitting:

help(dLOGNO, package=gamlss.dist)
$\endgroup$
  • 1
    $\begingroup$ I did not know about fixing the dispersion parameter (+1). $\endgroup$ – jbowman Jan 21 '12 at 17:37
  • $\begingroup$ I saw this solution in another post, I think. However, there are two problems. First, in this case only the summary is adjusted but the parameters I need to extract (residuals etc.) are not adjusted to the dispersion of 1, or am I wrong? Second, I cannot fit with family=Gamma because there are zeros in the data set (actually these are veeery small values but were set to zero). I will checkout the gamlss.dist package! $\endgroup$ – Jens Jan 22 '12 at 10:37
  • 1
    $\begingroup$ Well, the zeros-problem is not a problem with R or glm, but with mathematics, ... and if you have parameter estimates, the construction of residuals is trivial in R. Post that question in SO with an [r] tag and you will surely get a rapid response. $\endgroup$ – DWin Jan 22 '12 at 13:36
8
$\begingroup$

Lognormal is not an option because the log-normal distribution is not in the exponential family of distributions. Generalized linear models can only fit distributions from the exponential family.

I'm less clear why exponential is not an option, as the exponential distribution is in the exponential family (as you might hope). Other statistical software with which I am familiar allows fitting the exponential distribution as a GLM by treating it as a special case of the Gamma distribution with shape (aka scale or dispersion) parameter fixed at 1 rather than estimated. I can't see a way of fixing this parameter using R's glm() function, however. One alternative would be to use the survreg() function from the survival package with dist="exponential".

If you have response data $y$ that you believe follows a lognormal distribution, the usual way of fitting a regression model to it would be to log-transform it, as $\log(y)$ will have a normal distribution. The simplest case is then to fit an ordinary (i.e. not generalized) linear model. The resulting model is not quite the same model you would get if you could fit a GLM with a log link, however, as $\operatorname{E}(\log(Y)) \ne \log(\operatorname{E}(Y)).$

$\endgroup$
  • 8
    $\begingroup$ The lognormal is in the exponential family - it even says so in the very link you gave! See the second sentence here, and see this table, right above "Inverse Gaussian", with details of exactly how it is (i.e. $h(x), T(x), A(\theta)$ are given). This issue is a regular point of contention. If we restrict what we're talking about when we say "exponential family", then the lognormal may be excluded, but the definition given at your link includes it. $\endgroup$ – Glen_b Jul 9 '13 at 2:46
  • $\begingroup$ Do you have a reference for the statement that "Generalized linear models can only fit distributions from the exponential family"? $\endgroup$ – Henrik May 13 '18 at 11:20
5
$\begingroup$

Fitting a log-normal GLM has nothing to do with the distribution nor the link option of the glm() function. The term "log-normal" is quite confusing in this sense, but means that the response variable is normally distributed (family=gaussian), and a transformation is applied to this variable the following way:

log.glm <- glm(log(y)~x, family=gaussian, data=my.dat)

However, when comparing this log-normal glm with other glms using different distribution (e.g., gamma), the AIC() function should be corrected. Would anyone know an alternative to these erroneous AIC(), in this case?

$\endgroup$
  • 2
    $\begingroup$ Welcome to the site, @CHarma. If you have a question please click on the gray "ASK QUESTION" in the upper right corner, rather than including it in your answer. $\endgroup$ – gung Sep 16 '12 at 1:45
1
$\begingroup$

Try using the following command:

log.glm = glm(y ~ x, family=gaussian(link="log"), data=my.dat)

It works here and the AIC seems to be correct.

$\endgroup$
  • 7
    $\begingroup$ This answer is wrong. It would mean that the conditional distribution of y is Gaussian and the logged mean would equal the linear predictor. Certainly not what the OP describes. $\endgroup$ – Michael M Jul 20 '15 at 19:45

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.