9
$\begingroup$

I am using using a gamma generalized linear model (GLM) with an identity link. The independent variable is the compensation of a particular group.

Python's statsmodels summary is giving me a warning about the identity link function ("DomainWarning: The identity link function does not respect the domain of the Gamma family.") that I don't understand and would love some help with. Background: Only basic formal education in statistics and virtually no experience with GLMs beyond logistic regression.

Here's the relevant Python code:

model=statsmodels.genmod.generalized_linear_model.GLM(target, reducedFeatures, family=sm.families.Gamma(link=sm.families.links.identity)) results=model.fit() print(results.summary())

Here's the output: enter image description here

My question is this: In what way does an identity link not respect the domain of the Gamma family? The domain of the gamma family is 0 to infinity? I was also under the impression that the identity link wasn't doing much of anything i.e. it's keeping the independent variables as is and not transforming them/their relationship with the dependent variable. It sounds like a respectful link function ;)

Please correct me

$\endgroup$
  • $\begingroup$ The identity link means that the expected value of the dependent variable is just the linear predictor, as in a linear regression model. There's nothing to keep the expected value positive; for some values of the predictors, the expected value could be zero or negative. Hence "the identity link function does not respect the domain of the Gamma family". $\endgroup$ – The Laconic Jul 13 '18 at 23:01
8
$\begingroup$

The Gamma GLM model is:

$$ y \mid X \sim \text{Gamma} (\mu = f(X\beta), \phi) $$

Where $\mu$ is the expectation parameter, and $\phi$ is a dispersion parameter (the dispersion parameter is not estimated in the standard GLM framework), $X\beta$ is the linear predictor, $\beta$ are the parameters learned by the model, and $f$ is called the link function.

Note that, while $X\beta$ is allowed to take any real value, $f(X\beta)$ is modeling the expectation of a Gamma distribution, which must be a positive real number. This is what Python is telling you, the identity function is not guaranteed to map $X\beta$ to a positive real number, so does not always result in a valid mean parameter.

Cool. Thank you! All of my independent variables are positive, real numbers so I'm good to go, right?

Not necessarily, one of your estimated coefficients could be negative (your intercept is very negative).

Would you mind going into a bit more detail on what you mean? Why would the sign of the intercept have any impact on the coefficients? That doesn't make sense to me.

It has an effect on the mean parameter of your conditional Gamma distribution. Remember, your structure equation for the model is:

$$ \mu = f(X \beta) $$

and $\mu$ must be positive. Suppose that it is valid that all the values of your predictor variables be zero (I don't know if this is the case in your data, as I lack context for your features). Then, your prediction for this data point would be:

$$ \mu(x) = f \left( (1, 0, 0, \cdots, 0) \cdot \beta \right) = f(\text{Intercept}) $$

If you are using the identity link function this means that

$$ \mu(x) = \text{Intercept} $$

which is an invalid value of $\mu$ when the intercept is negative.

Again, due to contextual constraints of your data, you may avoid this situation, but it is mathematically possible.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Cool. Thank you! All of my independent variables are positive, real numbers so I'm good to go, right? $\endgroup$ – kalidurge Jul 13 '18 at 20:56
  • $\begingroup$ Not necessarily, one of your estimated coefficients could be negative (your intercept is very negative). $\endgroup$ – Matthew Drury Jul 13 '18 at 21:28
  • $\begingroup$ Would you mind going into a bit more detail on what you mean? Why would the sign of the intercept have any impact on the coefficients? That doesn't make sense to me. $\endgroup$ – kalidurge Jul 16 '18 at 15:06
  • $\begingroup$ @kalidurge I edited in an answer to your follow up. $\endgroup$ – Matthew Drury Jul 16 '18 at 16:06
  • $\begingroup$ Really helpful. I very much appreciate it! $\endgroup$ – kalidurge Jul 16 '18 at 16:43
1
$\begingroup$

Since I posted this question over a year ago, I've taken a class on generalized linear models and learned a lot. Since this post is viewed somewhat frequently, I thought I would add some guidance I wish I had at the time.

Link functions to consider for the Gamma model:

  • Log - Forces the predictions/output to "respect the domain" by ensuring all predicted values are positive
  • Reciprocal - Does not force the values to respect the domain but often works well. (It's used because it's the natural parameter of the canonical form of the Gamma model.) This is the default link function in R.

As a general rule, avoid the identity link function.

That said, you probably can and should avoid using the Gamma model in most situations. If you have data with significant skew, transform your target variable and run a standard linear regression model. The results will generally be easier to understand and just as good or better.

| cite | improve this answer | |
$\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.