26
$\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$
4
  • 1
    $\begingroup$ This should be on SO with an [r] tag. $\endgroup$
    – DWin
    Commented Jan 21, 2012 at 15:40
  • 6
    $\begingroup$ @DWin - I disagree for once - I often vote to migrate Qs to SO myself, but this question has significant statistical content. $\endgroup$
    – onestop
    Commented Jan 21, 2012 at 16:23
  • 1
    $\begingroup$ @onestop: I'm in belated agreement. R is just one of many stats environments with very similar solving mechanisms. Sorry it to me nine years to circle back. I voted to reopen. $\endgroup$
    – DWin
    Commented Aug 16, 2021 at 2:06
  • $\begingroup$ The package logNormReg does just that. cran.r-project.org/web/packages/logNormReg/index.html $\endgroup$
    – KuJ
    Commented Nov 18, 2021 at 23:14

5 Answers 5

15
$\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$
15
$\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
  • 3
    $\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$ Commented Sep 16, 2012 at 1:45
  • 1
    $\begingroup$ @CHarma is right. If the random variable X is log-normally distributed, then Y = ln(X) has a normal distribution. So you have to use family=gaussian $\endgroup$
    – igorkf
    Commented Apr 3, 2020 at 14:21
14
$\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$
4
  • 13
    $\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
    Commented Jul 9, 2013 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
    Commented May 13, 2018 at 11:20
  • $\begingroup$ I would think that the people who wrote glm would have checked the validity of this before including the option family=gaussian(link=log). $\endgroup$
    – abalter
    Commented Mar 5, 2020 at 19:28
  • 2
    $\begingroup$ @abalter family=gaussian(link=log) is not the same as lognormal regression. This is using the link function on the mean value as the log. Not to be confused with a log transformation of the response. $\endgroup$
    – Therkel
    Commented Dec 13, 2021 at 10:06
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$
3
  • 3
    $\begingroup$ I did not know about fixing the dispersion parameter (+1). $\endgroup$
    – jbowman
    Commented Jan 21, 2012 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
    Commented Jan 22, 2012 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
    Commented Jan 22, 2012 at 13:36
-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$
1
  • 9
    $\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
    Commented Jul 20, 2015 at 19:45

Your Answer

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

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