guide:8a3fa174fe: Difference between revisions
No edit summary |
mNo edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
In statistics, a '''generalized linear model''' ('''GLM''') is a flexible generalization of ordinary [[guide:F7d7868547|linear regression]]. The GLM generalizes linear regression by allowing the linear model to be related to the response variable via a ''link function'' and by allowing the magnitude of the variance of each measurement to be a function of its predicted value. | |||
==Intuition== | |||
Ordinary linear regression predicts the expected value of a given unknown quantity (the ''response variable'', a dependent variable) as a linear combination of a set of observed values (''predictors''). This implies that a constant change in a predictor leads to a constant change in the response variable (i.e. a ''linear-response model''). This is appropriate when the response variable can vary, to a good approximation, indefinitely in either direction, or more generally for any quantity that only varies by a relatively small amount compared to the variation in the predictive variables, e.g. human heights. | |||
However, these assumptions are inappropriate for some types of response variables. For example, in cases where the response variable is expected to be always positive and varying over a wide range, constant input changes lead to geometrically (i.e. exponentially) varying, rather than constantly varying, output changes. As an example, suppose a linear prediction model learns from some data (perhaps primarily drawn from large beaches) that a 10 degree temperature decrease would lead to 1,000 fewer people visiting the beach. This model is unlikely to generalize well over different sized beaches. More specifically, the problem is that if you use the model to predict the new attendance with a temperature drop of 10 for a beach that regularly receives 50 beachgoers, you would predict an impossible attendance value of −950. Logically, a more realistic model would instead predict a constant ''rate'' of increased beach attendance (e.g. an increase of 10 degrees leads to a doubling in beach attendance, and a drop of 10 degrees leads to a halving in attendance). Such a model is termed an ''exponential-response model'' (or ''[[log-linear model|log-linear model]]'', since the logarithm of the response is predicted to vary linearly). | |||
Similarly, a model that predicts a probability of making a yes/no choice (a [[Bernoulli distribution|Bernoulli variable]]) is even less suitable as a linear-response model, since probabilities are bounded on both ends (they must be between 0 and 1). Imagine, for example, a model that predicts the likelihood of a given person going to the beach as a function of temperature. A reasonable model might predict, for example, that a change in 10 degrees makes a person two times more or less likely to go to the beach. But what does "twice as likely" mean in terms of a probability? It cannot literally mean to double the probability value (e.g. 50% becomes 100%, 75% becomes 150%, etc.). Rather, it is the ''odds'' that are doubling: from 2:1 odds, to 4:1 odds, to 8:1 odds, etc. Such a model is a ''log-odds or [[Logistic regression|logistic]] model''. | |||
Generalized linear models cover all these situations by allowing for response variables that have arbitrary distributions (rather than simply [[normal distribution|normal distribution]]s), and for an arbitrary function of the response variable (the ''link function'') to vary linearly with the predictors (rather than assuming that the response itself must vary linearly). For example, the case above of predicted number of beach attendees would typically be modeled with a [[Poisson distribution|Poisson distribution]] and a log link, while the case of predicted probability of beach attendance would typically be modelled with a [[Bernoulli distribution|Bernoulli distribution]] (or [[binomial distribution|binomial distribution]], depending on exactly how the problem is phrased) and a log-odds (or ''[[logit|logit]]'') link function. | |||
==Overview== | |||
In a generalized linear model (GLM), each outcome <math>\mathbf{Y}</math> of the dependent variables is assumed to be generated from a particular [[probability distribution|distribution]] in an [[exponential family|exponential family]], a large class of [[probability distributions|probability distributions]] that includes the [[normal distribution|normal]], [[binomial distribution|binomial]], [[poisson distribution|Poisson]] and [[gamma distribution|gamma]] distributions, among others. The mean, <math>\mathbf{\mu}</math>, of the distribution depends on the independent variables, <math>\mathbf{X}</math>, through: | |||
<math display = "block">\operatorname{E}(\mathbf{Y}|\mathbf{X}) = \boldsymbol{\mu} = g^{-1}(\mathbf{X}\boldsymbol{\beta}) </math> | |||
where <math>\operatorname{E}[\mathbf{Y}|\mathbf{X}]</math> is the expected value of <math>\mathbf{Y}</math>conditional on <math>\mathbf{X}</math>; <math>\mathbf{X\beta}</math> is the ''linear predictor'', a linear combination of unknown parameters <math>\mathbf{\beta}</math>; <math>g</math> is the link function. | |||
In this framework, the variance is typically a function, <math>\operatorname{V}</math>, of the mean: | |||
<math display = "block"> \operatorname{Var}(\mathbf{Y}|\mathbf{X}) = \operatorname{V}(g^{-1}(\mathbf{X}\boldsymbol{\beta})). </math> | |||
It is convenient if <math>\operatorname{V}</math> follows from an exponential family of distributions, but it may simply be that the variance is a function of the predicted value. | |||
The unknown parameters, <math>\mathbf{\beta}</math>, are typically estimated with [[maximum likelihood|maximum likelihood]], maximum [[quasi-likelihood|quasi-likelihood]], or [[Bayesian probability|Bayesian]] techniques. | |||
== Model components == | |||
The GLM consists of three elements: | |||
: 1. A particular distribution for modeling <math> Y </math> from among those which are considered exponential families of probability distributions, | |||
: 2. A linear predictor <math>\eta = X \beta</math>, and | |||
: 3. A link function <math>g</math> such that <math>E(Y \mid X) = \mu = g^{-1}(\eta)</math>. | |||
=== Probability distribution === | |||
An '''overdispersed exponential family''' of distributions is a generalization of an [[exponential family|exponential family]] and the [[exponential dispersion model|exponential dispersion model]] of distributions and includes those families of probability distributions, parameterized by <math>\boldsymbol\theta</math> and <math>\tau</math>, whose density functions ''f'' (or [[probability mass function|probability mass function]], for the case of a [[discrete distribution|discrete distribution]]) can be expressed in the form | |||
<math display = "block"> f_Y(\mathbf{y} \mid \boldsymbol\theta, \tau) = h(\mathbf{y},\tau) \exp \left(\frac{\mathbf{b}(\boldsymbol\theta)^{\rm T}\mathbf{T}(\mathbf{y}) - A(\boldsymbol\theta)} {d(\tau)} \right). \,\!</math> | |||
The ''dispersion parameter'', <math>\tau</math>, typically is known and is usually related to the variance of the distribution. The functions <math>h(\mathbf{y},\tau)</math>, <math>\mathbf{b}(\boldsymbol\theta)</math>, <math>\mathbf{T}(\mathbf{y})</math>, <math>A(\boldsymbol\theta)</math>, and <math>d(\tau)</math> are known. Many common distributions are in this family, including the normal, exponential, gamma, Poisson, Bernoulli, and (for fixed number of trials) binomial, multinomial, and negative binomial. | |||
For scalar <math>\mathbf{y}</math> and <math>\boldsymbol\theta</math> (denoted <math>y</math> and <math>\theta</math> in this case), this reduces to | |||
<math display = "block"> f_Y(y \mid \theta, \tau) = h(y,\tau) \exp \left(\frac{b(\theta)T(y) - A(\theta)}{d(\tau)} \right). \,\!</math> | |||
<math>\boldsymbol\theta</math> is related to the mean of the distribution. If <math>\mathbf{b}(\boldsymbol\theta)</math> is the identity function, then the distribution is said to be in canonical form (or ''natural form''). Note that any distribution can be converted to canonical form by rewriting <math>\boldsymbol\theta</math> as <math>\boldsymbol\theta'</math> and then applying the transformation <math>\boldsymbol\theta = \mathbf{b}(\boldsymbol\theta')</math>. It is always possible to convert <math>A(\boldsymbol\theta)</math> in terms of the new parametrization, even if <math>\mathbf{b}(\boldsymbol\theta')</math> is not a one-to-one function. If, in addition, <math>\mathbf{T}(\mathbf{y})</math> is the identity and <math>\tau</math> is known, then <math>\boldsymbol\theta</math> is called the ''canonical parameter'' (or ''natural parameter'') and is related to the mean through | |||
<math display = "block"> \boldsymbol\mu = \operatorname{E}(\mathbf{y}) = \nabla A(\boldsymbol\theta). \,\!</math> | |||
For scalar <math>\mathbf{y}</math> and <math>\boldsymbol\theta</math>, this reduces to | |||
<math display = "block"> \mu = \operatorname{E}(y) = A'(\theta).</math> | |||
Under this scenario, the variance of the distribution can be shown to be<ref>{{harvnb|McCullagh|Nelder|1989}}, Chapter 2.</ref> | |||
<math display = "block">\operatorname{Var}(\mathbf{y}) = \nabla^2 A(\boldsymbol\theta) d(\tau). \,\!</math> | |||
For scalar <math>\mathbf{y}</math> and <math>\boldsymbol\theta</math>, this reduces to | |||
<math display = "block">\operatorname{Var}(y) = A''(\theta) d(\tau). \,\!</math> | |||
=== Linear predictor === | |||
The linear predictor is the quantity which incorporates the information about the independent variables into the model. The symbol ''η'' (Greek "eta") denotes a linear predictor. It is related to the expected value of the data through the link function. | |||
<math>\eta</math> is expressed as linear combinations (thus, "linear") of unknown parameters <math>\mathbf{\beta}</math>. The coefficients of the linear combination are represented as the matrix of independent variables <math>\mathbf{X}</math>. <math>\eta</math> can thus be expressed as <math> \eta = \mathbf{X}\boldsymbol{\beta}.\,</math> | |||
=== Link function === | |||
The link function provides the relationship between the linear predictor and the mean of the distribution function. There are many commonly used link functions, and their choice is informed by several considerations. There is always a well-defined ''canonical'' link function which is derived from the exponential of the response's [[density function|density function]]. However, in some cases it makes sense to try to match the domain of the link function to the range of the distribution function's mean, or use a non-canonical link function for algorithmic purposes, for example [[wikipedia:Probit model#Gibbs sampling|Bayesian probit regression]]. | |||
When using a distribution function with a canonical parameter <math>\theta</math>, the canonical link function is the function that expresses <math>\theta</math> in terms of <math>\mu</math>, i.e. <math>\theta = b(\mu)</math>. For the most common distributions, the mean <math>\mu</math> is one of the parameters in the standard form of the distribution's [[density function|density function]], and then <math>b(\mu)</math> is the function as defined above that maps the density function into its canonical form. When using the canonical link function, <math>b(\mu) = \theta = \mathbf{X}\boldsymbol{\beta}</math>, which allows <math>\mathbf{X}^{\rm T} \mathbf{Y}</math> to be a [[wikipedia:sufficiency (statistics)|sufficient statistic]] for <math>\boldsymbol{\beta}</math>. | |||
Following is a table of several exponential-family distributions in common use and the data they are typically used for, along with the canonical link functions and their inverses (sometimes referred to as the mean function, as done here). | |||
{| class="table table-bordered" style="background:white;" | |||
|+ Common distributions with typical uses and canonical link functions | |||
! Distribution !! Support of distribution !! Typical uses !! Link name !! Link function, <math>\mathbf{X}\boldsymbol{\beta}=g(\mu)\,\!</math> !! Mean function | |||
|- | |||
| [[normal distribution|Normal]] | |||
| real <math>(-\infty,+\infty)</math> || Linear-response data || Identity | |||
| <math>\mathbf{X}\boldsymbol{\beta}=\mu\,\!</math> || <math>\mu=\mathbf{X}\boldsymbol{\beta}\,\!</math> | |||
|- | |||
| [[exponential distribution|Exponential]] | |||
| rowspan="2" | real <math>(0,+\infty)</math> || rowspan="2" | Exponential-response data, scale parameters | |||
| rowspan="2" | Negative inverse | |||
| rowspan="2" | <math>\mathbf{X}\boldsymbol{\beta}=-\mu^{-1}\,\!</math> | |||
| rowspan="2" | <math>\mu=-(\mathbf{X}\boldsymbol{\beta})^{-1}\,\!</math> | |||
|- | |||
| [[gamma distribution|Gamma]] | |||
|- | |||
| [[Inverse Gaussian distribution|Inverse <br>Gaussian]] | |||
| real <math>(0, +\infty)</math> || || Inverse <br>squared || <math>\mathbf{X}\boldsymbol{\beta}=\mu^{-2}\,\!</math> || <math>\mu=(\mathbf{X}\boldsymbol{\beta})^{-1/2}\,\!</math> | |||
|- | |||
| [[Poisson distribution|Poisson]] | |||
| integer <math>0,1,2,\ldots</math> || count of occurrences in fixed amount of time/space || Log || <math>\mathbf{X}\boldsymbol{\beta} = \ln(\mu) \,\!</math> || <math>\mu=\exp (\mathbf{X}\boldsymbol{\beta}) \,\!</math> | |||
|- | |||
| [[Bernoulli distribution|Bernoulli]] | |||
| integer <math>\{0,1\}</math> || outcome of single yes/no occurrence | |||
| rowspan="5" | Logit | |||
| <math>\mathbf{X}\boldsymbol{\beta}=\ln \left(\frac \mu {1-\mu}\right) \,\!</math> | |||
| rowspan="5" | <math>\mu=\frac{\exp(\mathbf{X}\boldsymbol{\beta})}{1 + \exp(\mathbf{X}\boldsymbol{\beta})} = \frac 1 {1 + \exp(-\mathbf{X} \boldsymbol{\beta})} \,\!</math> | |||
|- | |||
| [[binomial distribution|Binomial]] | |||
| integer <math>0,1,\ldots,N</math> || count of # of "yes" occurrences out of N yes/no occurrences | |||
|<math>\mathbf{X}\boldsymbol{\beta}=\ln \left(\frac \mu {n-\mu}\right) \,\!</math> | |||
|- | |||
| rowspan=2| [[categorical distribution|Categorical]] | |||
| integer <math>[0,K)</math>|| rowspan=2| outcome of single K-way occurrence | |||
| rowspan="3" |<math>\mathbf{X}\boldsymbol{\beta}=\ln \left(\frac \mu {1-\mu}\right) \,\!</math> | |||
|- | |||
| K-vector of integer <math>[0,1]</math>, where exactly one element in the vector has the value 1 | |||
|- | |||
| [[multinomial distribution|Multinomial]] | |||
| <math>K</math>-vector of integer <math>[0,N]</math> || count of occurrences of different types (1 .. <math>K</math>) out of <math>N</math> total <math>K</math>-way occurrences | |||
|} | |||
In the cases of the exponential and gamma distributions, the domain of the canonical link function is not the same as the permitted range of the mean. In particular, the linear predictor may be positive, which would give an impossible negative mean. When maximizing the likelihood, precautions must be taken to avoid this. An alternative is to use a noncanonical link function. | |||
In the case of the Bernoulli, binomial, categorical and multinomial distributions, the support of the distributions is not the same type of data as the parameter being predicted. In all of these cases, the predicted parameter is one or more probabilities, i.e. real numbers in the range <math>[0,1]</math>. The resulting model is known as ''[[logistic regression|logistic regression]]'' (or ''[[multinomial logistic regression|multinomial logistic regression]]'' in the case that K-way rather than binary values are being predicted). | |||
For the Bernoulli and binomial distributions, the parameter is a single probability, indicating the likelihood of occurrence of a single event. The Bernoulli still satisfies the basic condition of the generalized linear model in that, even though a single outcome will always be either 0 or 1, the ''expected value'' will nonetheless be a real-valued probability, i.e. the probability of occurrence of a "yes" (or 1) outcome. Similarly, in a binomial distribution, the expected value is <math>Np</math>, i.e. the expected proportion of "yes" outcomes will be the probability to be predicted. | |||
For categorical and multinomial distributions, the parameter to be predicted is a <math>K</math>-vector of probabilities, with the further restriction that all probabilities must add up to 1. Each probability indicates the likelihood of occurrence of one of the <math>K</math> possible values. For the multinomial distribution, and for the vector form of the categorical distribution, the expected values of the elements of the vector can be related to the predicted probabilities similarly to the binomial and Bernoulli distributions. | |||
== Maximum likelihood == | |||
The [[maximum likelihood|maximum likelihood]] estimates can be found using an [[wikipedia:iteratively reweighted least squares|iteratively reweighted least squares]] algorithm or a [[Newton's method in optimization|Newton's method]] with updates of the form: | |||
<math display = "block"> \boldsymbol\beta^{(t+1)} = \boldsymbol\beta^{(t)} + \mathcal{J}^{-1}(\boldsymbol\beta^{(t)}) u(\boldsymbol\beta^{(t)}), </math> | |||
where <math>\mathcal{J}(\boldsymbol\beta^{(t)})</math> is the [[wikipedia:observed information|observed information matrix]] (the negative of the [[wikipedia:Hessian matrix|Hessian matrix]]) and <math>u(\boldsymbol\beta^{(t)})</math> is the [[wikipedia:score (statistics)|score function]]; or a [[wikipedia:Scoring algorithm|Fisher's scoring]] method: | |||
<math display = "block"> \boldsymbol\beta^{(t+1)} = \boldsymbol\beta^{(t)} + \mathcal{I}^{-1}(\boldsymbol\beta^{(t)}) u(\boldsymbol\beta^{(t)}), </math> | |||
where <math>\mathcal{I}(\boldsymbol\beta^{(t)})</math> is the [[wikipedia:Fisher information|Fisher information]] matrix. Note that if the canonical link function is used, then they are the same.{{sfn|McCullagh|Nelder|1989|p=43}} | |||
== Examples == | |||
=== General linear models === | |||
A possible point of confusion has to do with the distinction between generalized linear models and [[general linear model|general linear model]]s, two broad statistical models. Co-originator John Nelder has expressed regret over this terminology.<ref>{{cite journal |last= Senn|first=Stephen |year=2003 |title=A conversation with John Nelder |journal=Statistical Science |volume=18 |issue=1 |pages=118–131 |doi=10.1214/ss/1056397489|quote=I suspect we should have found some more fancy name for it that would have stuck and not been confused with the general linear model, although general and generalized are not quite the same. I can see why it might have been better to have thought of something else.|doi-access=free }}</ref> | |||
The general linear model may be viewed as a special case of the generalized linear model with identity link and responses normally distributed. As most exact results of interest are obtained only for the general linear model, the general linear model has undergone a somewhat longer historical development. Results for the generalized linear model with non-identity link are asymptotic (tending to work well with large samples). | |||
=== Linear regression === | |||
A simple, very important example of a generalized linear model (also an example of a general linear model) is [[guide:F7d7868547|linear regression]]. In linear regression, the use of the [[guide:F7d7868547#Linear Least Squares|least-squares]] estimator is justified by the [[Gauss–Markov theorem|Gauss–Markov theorem]], which does not assume that the distribution is normal. | |||
From the perspective of generalized linear models, however, it is useful to suppose that the distribution function is the normal distribution with constant variance and the link function is the identity, which is the canonical link if the variance is known. Under these assumptions, the least-squares estimator is obtained as the maximum-likelihood parameter estimate. | |||
For the normal distribution, the generalized linear model has a closed form expression for the maximum-likelihood estimates, which is convenient. Most other GLMs lack closed form estimates. | |||
=== Binary data === | |||
When the response data, <math>Y</math>, are binary (taking on only values 0 and 1), the distribution function is generally chosen to be the [[Bernoulli distribution|Bernoulli distribution]] and the interpretation of <math>\mu_i</math> is then the probability, <math>p</math>, of <math>Y_i</math> taking on the value one. | |||
There are several popular link functions for binomial functions. | |||
==== Logit link function ==== | |||
The most typical link function is the canonical logit link: | |||
<math display = "block">g(p) = \ln \left( { p \over 1-p } \right).</math> | |||
GLMs with this setup are [[logistic regression|logistic regression]] models (or ''logit models''). | |||
==== Probit link function as popular choice of inverse cumulative distribution function ==== | |||
Alternatively, the inverse of any continuous [[cumulative distribution function|cumulative distribution function]] (CDF) can be used for the link since the CDF's range is <math>[0,1]</math>, the range of the binomial mean. The [[Normal distribution#Cumulative distribution function|normal CDF]] <math>\Phi</math> is a popular choice and yields the [[probit model|probit model]]. Its link is | |||
<math display = "block">g(p) = \Phi^{-1}(p).\,\!</math> | |||
The reason for the use of the probit model is that a constant scaling of the input variable to a normal CDF (which can be absorbed through equivalent scaling of all of the parameters) yields a function that is practically identical to the logit function, but probit models are more tractable in some situations than logit models. (In a Bayesian setting in which normally distributed [[prior distribution|prior distribution]]s are placed on the parameters, the relationship between the normal priors and the normal CDF link function means that a [[probit model|probit model]] can be computed using [[wikipedia:Gibbs sampling|Gibbs sampling]], while a logit model generally cannot.) | |||
==== Complementary log-log (cloglog) ==== | |||
The complementary log-log function may also be used: | |||
<math display = "block">g(p) = \log(-\log(1-p)).</math> | |||
This link function is asymmetric and will often produce different results from the logit and probit link functions.<ref>{{Cite web|url=http://www.stat.ualberta.ca/~kcarrier/STAT562/comp_log_log.pdf|title=Complementary Log-log Model}}</ref> The cloglog model corresponds to applications where we observe either zero events (e.g., defects) or one or more, where the number of events is assumed to follow the [[Poisson distribution|Poisson distribution]].<ref>{{Cite web|url=https://bayesium.com/which-link-function-logit-probit-or-cloglog/|title=Which Link Function — Logit, Probit, or Cloglog?|date=2015-08-14|website=Bayesium Analytics|language=en-US|access-date=2019-03-17}}</ref> The Poisson assumption means that | |||
<math display = "block">\Pr(0) = \exp(-\mu),</math> | |||
where ''μ'' is a positive number denoting the expected number of events. If <math>p</math> represents the proportion of observations with at least one event, its complement | |||
<math display = "block">(1-p) = \Pr(0) = \exp(-\mu),</math> | |||
and then | |||
<math display = "block">(-\log(1-p)) = \mu.</math> | |||
A linear model requires the response variable to take values over the entire real line. Since ''μ'' must be positive, we can enforce that by taking the logarithm, and letting log(''μ'') be a linear model. This produces the "cloglog" transformation | |||
<math display = "block">\log(-\log(1-p)) = \log(\mu).</math> | |||
==== Identity link ==== | |||
The identity link ''g(p) = p'' is also sometimes used for binomial data to yield a [[linear probability model|linear probability model]]. However, the identity link can predict nonsense "probabilities" less than zero or greater than one. This can be avoided by using a transformation like cloglog, probit or logit (or any inverse cumulative distribution function). A primary merit of the identity link is that it can be estimated using linear math—and other standard link functions are approximately linear matching the identity link near <math>p</math> = 0.5. | |||
==== Variance function ==== | |||
The [[variance function|variance function]] for "quasibinomial" data is: | |||
<math display = "block">\operatorname{Var}(Y_i)= \tau\mu_i (1-\mu_i)\,\!</math> | |||
where the dispersion parameter ''τ'' is exactly 1 for the binomial distribution. Indeed, the standard binomial likelihood omits ''τ''. When it is present, the model is called "quasibinomial", and the modified likelihood is called a [[quasi-likelihood|quasi-likelihood]], since it is not generally the likelihood corresponding to any real family of probability distributions. If ''τ'' exceeds 1, the model is said to exhibit [[overdispersion|overdispersion]]. | |||
===Multinomial regression=== | |||
The binomial case may be easily extended to allow for a [[multinomial distribution|multinomial distribution]] as the response (also, a Generalized Linear Model for counts, with a constrained total). There are two ways in which this is not usually done: | |||
====Ordered response==== | |||
If the response variable is ordinal, then one may fit a model function of the form: | |||
<math display = "block"> g(\mu_m) = \eta_m = \beta_0 + X_1 \beta_1 + \cdots + X_p \beta_p + \gamma_2 + \cdots + \gamma_m = \eta_1 + \gamma_2 + \cdots + \gamma_m </math> | |||
where <math> \mu_m = \operatorname{P}(Y \leq m)</math> for <math>m >2</math>. Different links <math>g</math> lead to [[ordinal regression|ordinal regression]] models like [[wikipedia:Ordered logit|proportional odds model]]s or [[wikipedia:ordered probit|ordered probit]] models. | |||
====Unordered response==== | |||
If the response variable is a nominal measurement, or the data do not satisfy the assumptions of an ordered model, one may fit a model of the following form: | |||
<math display = "block"> g(\mu_m) = \eta_m = \beta_{m,0} + X_1 \beta_{m,1} + \cdots + X_p \beta_{m,p}</math> | |||
where <math> \mu_m = \mathrm{P}(Y = m \mid Y \in \{1,m\} )</math> for <math>m >2</math>. Different links <math>g</math> lead to [[wikipedia:multinomial logit|multinomial logit]] or [[wikipedia:multinomial probit|multinomial probit]] models. These are more general than the ordered response models, and more parameters are estimated. | |||
===Count data=== | |||
Another example of generalized linear models includes [[Poisson regression|Poisson regression]] which models [[count data|count data]] using the [[Poisson distribution|Poisson distribution]]. The link is typically the logarithm, the canonical link. | |||
The variance function is proportional to the mean | |||
<math display = "block">\operatorname{var}(Y_i) = \tau\mu_i,\, </math> | |||
where the dispersion parameter ''τ'' is typically fixed at exactly one. When it is not, the resulting [[quasi-likelihood|quasi-likelihood]] model is often described as Poisson with [[overdispersion|overdispersion]] or ''quasi-Poisson''. | |||
== References == | |||
{{Reflist}} | |||
== Bibliography == | |||
{{refbegin}} | |||
* {{cite book |last1 = Hastie |first1 = T. J. |author1-link = Trevor Hastie |last2 = Tibshirani |first2 = R. J. |author2-link = Robert Tibshirani |title = Generalized Additive Models |publisher = Chapman & Hall/CRC |year = 1990 |isbn = 978-0-412-34390-2 }} | |||
* {{cite book |last1 = Madsen |first1 = Henrik |last2 = Thyregod |first2 = Poul |title = Introduction to General and Generalized Linear Models |year = 2011 |publisher = Chapman & Hall/CRCC |isbn = 978-1-4200-9155-7 }} | |||
* {{cite book |last1 = McCullagh |first1 = Peter |author1-link = Peter McCullagh |last2 = Nelder |first2 = John |author2-link = John Nelder |title = Generalized Linear Models |edition = 2nd |publisher = Chapman and Hall/CRC |location = [[Boca Raton|Boca Raton]], FL |year = 1989 |isbn = 0-412-31760-5 }} | |||
* {{cite book |last = Wood |first = Simon |year = 2006 |title = Generalized Additive Models: An Introduction with R |publisher = Chapman & Hall/CRC |isbn = 1-58488-474-6 }} | |||
{{refend}} | |||
==Further reading== | |||
*{{cite book | last = Dunn| first = P.K. |author2=Smyth, G.K. | title = Generalized Linear Models With Examples in R | publisher = New York: Springer | year = 2018 | isbn=978-1-4419-0118-7 | doi=10.1007/978-1-4419-0118-7}} | |||
*{{cite book | last = Dobson| first = A.J. |author2=Barnett, A.G. | title = Introduction to Generalized Linear Models |edition = 3rd | publisher = Boca Raton, FL: Chapman and Hall/CRC | year = 2008 |isbn = 978-1-58488-165-0}} | |||
*{{cite book | last = Hardin| first = James |author2=Hilbe, Joseph |author-link2=Joseph Hilbe | title = Generalized Linear Models and Extensions | publisher = College Station: Stata Press | year = 2007 |edition=2nd |isbn=978-1-59718-014-6 }} | |||
==Wikipedia References== | |||
*{{cite web |url = https://en.wikipedia.org/w/index.php?title=Generalized_linear_model&oldid=1101104655|title= Generalized linear model | author = Wikipedia contributors |website= Wikipedia |publisher= Wikipedia |access-date = 17 August 2022 }} |
Latest revision as of 22:36, 12 April 2024
In statistics, a generalized linear model (GLM) is a flexible generalization of ordinary linear regression. The GLM generalizes linear regression by allowing the linear model to be related to the response variable via a link function and by allowing the magnitude of the variance of each measurement to be a function of its predicted value.
Intuition
Ordinary linear regression predicts the expected value of a given unknown quantity (the response variable, a dependent variable) as a linear combination of a set of observed values (predictors). This implies that a constant change in a predictor leads to a constant change in the response variable (i.e. a linear-response model). This is appropriate when the response variable can vary, to a good approximation, indefinitely in either direction, or more generally for any quantity that only varies by a relatively small amount compared to the variation in the predictive variables, e.g. human heights.
However, these assumptions are inappropriate for some types of response variables. For example, in cases where the response variable is expected to be always positive and varying over a wide range, constant input changes lead to geometrically (i.e. exponentially) varying, rather than constantly varying, output changes. As an example, suppose a linear prediction model learns from some data (perhaps primarily drawn from large beaches) that a 10 degree temperature decrease would lead to 1,000 fewer people visiting the beach. This model is unlikely to generalize well over different sized beaches. More specifically, the problem is that if you use the model to predict the new attendance with a temperature drop of 10 for a beach that regularly receives 50 beachgoers, you would predict an impossible attendance value of −950. Logically, a more realistic model would instead predict a constant rate of increased beach attendance (e.g. an increase of 10 degrees leads to a doubling in beach attendance, and a drop of 10 degrees leads to a halving in attendance). Such a model is termed an exponential-response model (or log-linear model, since the logarithm of the response is predicted to vary linearly).
Similarly, a model that predicts a probability of making a yes/no choice (a Bernoulli variable) is even less suitable as a linear-response model, since probabilities are bounded on both ends (they must be between 0 and 1). Imagine, for example, a model that predicts the likelihood of a given person going to the beach as a function of temperature. A reasonable model might predict, for example, that a change in 10 degrees makes a person two times more or less likely to go to the beach. But what does "twice as likely" mean in terms of a probability? It cannot literally mean to double the probability value (e.g. 50% becomes 100%, 75% becomes 150%, etc.). Rather, it is the odds that are doubling: from 2:1 odds, to 4:1 odds, to 8:1 odds, etc. Such a model is a log-odds or logistic model.
Generalized linear models cover all these situations by allowing for response variables that have arbitrary distributions (rather than simply normal distributions), and for an arbitrary function of the response variable (the link function) to vary linearly with the predictors (rather than assuming that the response itself must vary linearly). For example, the case above of predicted number of beach attendees would typically be modeled with a Poisson distribution and a log link, while the case of predicted probability of beach attendance would typically be modelled with a Bernoulli distribution (or binomial distribution, depending on exactly how the problem is phrased) and a log-odds (or logit) link function.
Overview
In a generalized linear model (GLM), each outcome [math]\mathbf{Y}[/math] of the dependent variables is assumed to be generated from a particular distribution in an exponential family, a large class of probability distributions that includes the normal, binomial, Poisson and gamma distributions, among others. The mean, [math]\mathbf{\mu}[/math], of the distribution depends on the independent variables, [math]\mathbf{X}[/math], through:
where [math]\operatorname{E}[\mathbf{Y}|\mathbf{X}][/math] is the expected value of [math]\mathbf{Y}[/math]conditional on [math]\mathbf{X}[/math]; [math]\mathbf{X\beta}[/math] is the linear predictor, a linear combination of unknown parameters [math]\mathbf{\beta}[/math]; [math]g[/math] is the link function.
In this framework, the variance is typically a function, [math]\operatorname{V}[/math], of the mean:
It is convenient if [math]\operatorname{V}[/math] follows from an exponential family of distributions, but it may simply be that the variance is a function of the predicted value.
The unknown parameters, [math]\mathbf{\beta}[/math], are typically estimated with maximum likelihood, maximum quasi-likelihood, or Bayesian techniques.
Model components
The GLM consists of three elements:
- 1. A particular distribution for modeling [math] Y [/math] from among those which are considered exponential families of probability distributions,
- 2. A linear predictor [math]\eta = X \beta[/math], and
- 3. A link function [math]g[/math] such that [math]E(Y \mid X) = \mu = g^{-1}(\eta)[/math].
Probability distribution
An overdispersed exponential family of distributions is a generalization of an exponential family and the exponential dispersion model of distributions and includes those families of probability distributions, parameterized by [math]\boldsymbol\theta[/math] and [math]\tau[/math], whose density functions f (or probability mass function, for the case of a discrete distribution) can be expressed in the form
The dispersion parameter, [math]\tau[/math], typically is known and is usually related to the variance of the distribution. The functions [math]h(\mathbf{y},\tau)[/math], [math]\mathbf{b}(\boldsymbol\theta)[/math], [math]\mathbf{T}(\mathbf{y})[/math], [math]A(\boldsymbol\theta)[/math], and [math]d(\tau)[/math] are known. Many common distributions are in this family, including the normal, exponential, gamma, Poisson, Bernoulli, and (for fixed number of trials) binomial, multinomial, and negative binomial.
For scalar [math]\mathbf{y}[/math] and [math]\boldsymbol\theta[/math] (denoted [math]y[/math] and [math]\theta[/math] in this case), this reduces to
[math]\boldsymbol\theta[/math] is related to the mean of the distribution. If [math]\mathbf{b}(\boldsymbol\theta)[/math] is the identity function, then the distribution is said to be in canonical form (or natural form). Note that any distribution can be converted to canonical form by rewriting [math]\boldsymbol\theta[/math] as [math]\boldsymbol\theta'[/math] and then applying the transformation [math]\boldsymbol\theta = \mathbf{b}(\boldsymbol\theta')[/math]. It is always possible to convert [math]A(\boldsymbol\theta)[/math] in terms of the new parametrization, even if [math]\mathbf{b}(\boldsymbol\theta')[/math] is not a one-to-one function. If, in addition, [math]\mathbf{T}(\mathbf{y})[/math] is the identity and [math]\tau[/math] is known, then [math]\boldsymbol\theta[/math] is called the canonical parameter (or natural parameter) and is related to the mean through
For scalar [math]\mathbf{y}[/math] and [math]\boldsymbol\theta[/math], this reduces to
Under this scenario, the variance of the distribution can be shown to be[1]
For scalar [math]\mathbf{y}[/math] and [math]\boldsymbol\theta[/math], this reduces to
Linear predictor
The linear predictor is the quantity which incorporates the information about the independent variables into the model. The symbol η (Greek "eta") denotes a linear predictor. It is related to the expected value of the data through the link function.
[math]\eta[/math] is expressed as linear combinations (thus, "linear") of unknown parameters [math]\mathbf{\beta}[/math]. The coefficients of the linear combination are represented as the matrix of independent variables [math]\mathbf{X}[/math]. [math]\eta[/math] can thus be expressed as [math] \eta = \mathbf{X}\boldsymbol{\beta}.\,[/math]
Link function
The link function provides the relationship between the linear predictor and the mean of the distribution function. There are many commonly used link functions, and their choice is informed by several considerations. There is always a well-defined canonical link function which is derived from the exponential of the response's density function. However, in some cases it makes sense to try to match the domain of the link function to the range of the distribution function's mean, or use a non-canonical link function for algorithmic purposes, for example Bayesian probit regression.
When using a distribution function with a canonical parameter [math]\theta[/math], the canonical link function is the function that expresses [math]\theta[/math] in terms of [math]\mu[/math], i.e. [math]\theta = b(\mu)[/math]. For the most common distributions, the mean [math]\mu[/math] is one of the parameters in the standard form of the distribution's density function, and then [math]b(\mu)[/math] is the function as defined above that maps the density function into its canonical form. When using the canonical link function, [math]b(\mu) = \theta = \mathbf{X}\boldsymbol{\beta}[/math], which allows [math]\mathbf{X}^{\rm T} \mathbf{Y}[/math] to be a sufficient statistic for [math]\boldsymbol{\beta}[/math].
Following is a table of several exponential-family distributions in common use and the data they are typically used for, along with the canonical link functions and their inverses (sometimes referred to as the mean function, as done here).
Distribution | Support of distribution | Typical uses | Link name | Link function, [math]\mathbf{X}\boldsymbol{\beta}=g(\mu)\,\![/math] | Mean function |
---|---|---|---|---|---|
Normal | real [math](-\infty,+\infty)[/math] | Linear-response data | Identity | [math]\mathbf{X}\boldsymbol{\beta}=\mu\,\![/math] | [math]\mu=\mathbf{X}\boldsymbol{\beta}\,\![/math] |
Exponential | real [math](0,+\infty)[/math] | Exponential-response data, scale parameters | Negative inverse | [math]\mathbf{X}\boldsymbol{\beta}=-\mu^{-1}\,\![/math] | [math]\mu=-(\mathbf{X}\boldsymbol{\beta})^{-1}\,\![/math] |
Gamma | |||||
Inverse Gaussian |
real [math](0, +\infty)[/math] | Inverse squared |
[math]\mathbf{X}\boldsymbol{\beta}=\mu^{-2}\,\![/math] | [math]\mu=(\mathbf{X}\boldsymbol{\beta})^{-1/2}\,\![/math] | |
Poisson | integer [math]0,1,2,\ldots[/math] | count of occurrences in fixed amount of time/space | Log | [math]\mathbf{X}\boldsymbol{\beta} = \ln(\mu) \,\![/math] | [math]\mu=\exp (\mathbf{X}\boldsymbol{\beta}) \,\![/math] |
Bernoulli | integer [math]\{0,1\}[/math] | outcome of single yes/no occurrence | Logit | [math]\mathbf{X}\boldsymbol{\beta}=\ln \left(\frac \mu {1-\mu}\right) \,\![/math] | [math]\mu=\frac{\exp(\mathbf{X}\boldsymbol{\beta})}{1 + \exp(\mathbf{X}\boldsymbol{\beta})} = \frac 1 {1 + \exp(-\mathbf{X} \boldsymbol{\beta})} \,\![/math] |
Binomial | integer [math]0,1,\ldots,N[/math] | count of # of "yes" occurrences out of N yes/no occurrences | [math]\mathbf{X}\boldsymbol{\beta}=\ln \left(\frac \mu {n-\mu}\right) \,\![/math] | ||
Categorical | integer [math][0,K)[/math] | outcome of single K-way occurrence | [math]\mathbf{X}\boldsymbol{\beta}=\ln \left(\frac \mu {1-\mu}\right) \,\![/math] | ||
K-vector of integer [math][0,1][/math], where exactly one element in the vector has the value 1 | |||||
Multinomial | [math]K[/math]-vector of integer [math][0,N][/math] | count of occurrences of different types (1 .. [math]K[/math]) out of [math]N[/math] total [math]K[/math]-way occurrences |
In the cases of the exponential and gamma distributions, the domain of the canonical link function is not the same as the permitted range of the mean. In particular, the linear predictor may be positive, which would give an impossible negative mean. When maximizing the likelihood, precautions must be taken to avoid this. An alternative is to use a noncanonical link function.
In the case of the Bernoulli, binomial, categorical and multinomial distributions, the support of the distributions is not the same type of data as the parameter being predicted. In all of these cases, the predicted parameter is one or more probabilities, i.e. real numbers in the range [math][0,1][/math]. The resulting model is known as logistic regression (or multinomial logistic regression in the case that K-way rather than binary values are being predicted).
For the Bernoulli and binomial distributions, the parameter is a single probability, indicating the likelihood of occurrence of a single event. The Bernoulli still satisfies the basic condition of the generalized linear model in that, even though a single outcome will always be either 0 or 1, the expected value will nonetheless be a real-valued probability, i.e. the probability of occurrence of a "yes" (or 1) outcome. Similarly, in a binomial distribution, the expected value is [math]Np[/math], i.e. the expected proportion of "yes" outcomes will be the probability to be predicted.
For categorical and multinomial distributions, the parameter to be predicted is a [math]K[/math]-vector of probabilities, with the further restriction that all probabilities must add up to 1. Each probability indicates the likelihood of occurrence of one of the [math]K[/math] possible values. For the multinomial distribution, and for the vector form of the categorical distribution, the expected values of the elements of the vector can be related to the predicted probabilities similarly to the binomial and Bernoulli distributions.
Maximum likelihood
The maximum likelihood estimates can be found using an iteratively reweighted least squares algorithm or a Newton's method with updates of the form:
where [math]\mathcal{J}(\boldsymbol\beta^{(t)})[/math] is the observed information matrix (the negative of the Hessian matrix) and [math]u(\boldsymbol\beta^{(t)})[/math] is the score function; or a Fisher's scoring method:
where [math]\mathcal{I}(\boldsymbol\beta^{(t)})[/math] is the Fisher information matrix. Note that if the canonical link function is used, then they are the same.[2]
Examples
General linear models
A possible point of confusion has to do with the distinction between generalized linear models and general linear models, two broad statistical models. Co-originator John Nelder has expressed regret over this terminology.[3]
The general linear model may be viewed as a special case of the generalized linear model with identity link and responses normally distributed. As most exact results of interest are obtained only for the general linear model, the general linear model has undergone a somewhat longer historical development. Results for the generalized linear model with non-identity link are asymptotic (tending to work well with large samples).
Linear regression
A simple, very important example of a generalized linear model (also an example of a general linear model) is linear regression. In linear regression, the use of the least-squares estimator is justified by the Gauss–Markov theorem, which does not assume that the distribution is normal.
From the perspective of generalized linear models, however, it is useful to suppose that the distribution function is the normal distribution with constant variance and the link function is the identity, which is the canonical link if the variance is known. Under these assumptions, the least-squares estimator is obtained as the maximum-likelihood parameter estimate.
For the normal distribution, the generalized linear model has a closed form expression for the maximum-likelihood estimates, which is convenient. Most other GLMs lack closed form estimates.
Binary data
When the response data, [math]Y[/math], are binary (taking on only values 0 and 1), the distribution function is generally chosen to be the Bernoulli distribution and the interpretation of [math]\mu_i[/math] is then the probability, [math]p[/math], of [math]Y_i[/math] taking on the value one.
There are several popular link functions for binomial functions.
Logit link function
The most typical link function is the canonical logit link:
GLMs with this setup are logistic regression models (or logit models).
Probit link function as popular choice of inverse cumulative distribution function
Alternatively, the inverse of any continuous cumulative distribution function (CDF) can be used for the link since the CDF's range is [math][0,1][/math], the range of the binomial mean. The normal CDF [math]\Phi[/math] is a popular choice and yields the probit model. Its link is
The reason for the use of the probit model is that a constant scaling of the input variable to a normal CDF (which can be absorbed through equivalent scaling of all of the parameters) yields a function that is practically identical to the logit function, but probit models are more tractable in some situations than logit models. (In a Bayesian setting in which normally distributed prior distributions are placed on the parameters, the relationship between the normal priors and the normal CDF link function means that a probit model can be computed using Gibbs sampling, while a logit model generally cannot.)
Complementary log-log (cloglog)
The complementary log-log function may also be used:
This link function is asymmetric and will often produce different results from the logit and probit link functions.[4] The cloglog model corresponds to applications where we observe either zero events (e.g., defects) or one or more, where the number of events is assumed to follow the Poisson distribution.[5] The Poisson assumption means that
where μ is a positive number denoting the expected number of events. If [math]p[/math] represents the proportion of observations with at least one event, its complement
and then
A linear model requires the response variable to take values over the entire real line. Since μ must be positive, we can enforce that by taking the logarithm, and letting log(μ) be a linear model. This produces the "cloglog" transformation
Identity link
The identity link g(p) = p is also sometimes used for binomial data to yield a linear probability model. However, the identity link can predict nonsense "probabilities" less than zero or greater than one. This can be avoided by using a transformation like cloglog, probit or logit (or any inverse cumulative distribution function). A primary merit of the identity link is that it can be estimated using linear math—and other standard link functions are approximately linear matching the identity link near [math]p[/math] = 0.5.
Variance function
The variance function for "quasibinomial" data is:
where the dispersion parameter τ is exactly 1 for the binomial distribution. Indeed, the standard binomial likelihood omits τ. When it is present, the model is called "quasibinomial", and the modified likelihood is called a quasi-likelihood, since it is not generally the likelihood corresponding to any real family of probability distributions. If τ exceeds 1, the model is said to exhibit overdispersion.
Multinomial regression
The binomial case may be easily extended to allow for a multinomial distribution as the response (also, a Generalized Linear Model for counts, with a constrained total). There are two ways in which this is not usually done:
Ordered response
If the response variable is ordinal, then one may fit a model function of the form:
where [math] \mu_m = \operatorname{P}(Y \leq m)[/math] for [math]m \gt2[/math]. Different links [math]g[/math] lead to ordinal regression models like proportional odds models or ordered probit models.
Unordered response
If the response variable is a nominal measurement, or the data do not satisfy the assumptions of an ordered model, one may fit a model of the following form:
where [math] \mu_m = \mathrm{P}(Y = m \mid Y \in \{1,m\} )[/math] for [math]m \gt2[/math]. Different links [math]g[/math] lead to multinomial logit or multinomial probit models. These are more general than the ordered response models, and more parameters are estimated.
Count data
Another example of generalized linear models includes Poisson regression which models count data using the Poisson distribution. The link is typically the logarithm, the canonical link.
The variance function is proportional to the mean
where the dispersion parameter τ is typically fixed at exactly one. When it is not, the resulting quasi-likelihood model is often described as Poisson with overdispersion or quasi-Poisson.
References
- McCullagh & Nelder 1989, Chapter 2.
- McCullagh & Nelder 1989, p. 43.
- Senn, Stephen (2003). "A conversation with John Nelder". Statistical Science 18 (1): 118–131. doi: . “I suspect we should have found some more fancy name for it that would have stuck and not been confused with the general linear model, although general and generalized are not quite the same. I can see why it might have been better to have thought of something else.”
- "Complementary Log-log Model" (PDF).
- "Which Link Function — Logit, Probit, or Cloglog?". Bayesium Analytics (in English). 2015-08-14. Retrieved 2019-03-17.
Bibliography
- Hastie, T. J.; Tibshirani, R. J. (1990). Generalized Additive Models. Chapman & Hall/CRC. ISBN 978-0-412-34390-2.
- Madsen, Henrik; Thyregod, Poul (2011). Introduction to General and Generalized Linear Models. Chapman & Hall/CRCC. ISBN 978-1-4200-9155-7.
- McCullagh, Peter; Nelder, John (1989). Generalized Linear Models (2nd ed.). Boca Raton, FL: Chapman and Hall/CRC. ISBN 0-412-31760-5.
- Wood, Simon (2006). Generalized Additive Models: An Introduction with R. Chapman & Hall/CRC. ISBN 1-58488-474-6.
Further reading
- Dunn, P.K.; Smyth, G.K. (2018). Generalized Linear Models With Examples in R. New York: Springer. doi:10.1007/978-1-4419-0118-7. ISBN 978-1-4419-0118-7.
- Dobson, A.J.; Barnett, A.G. (2008). Introduction to Generalized Linear Models (3rd ed.). Boca Raton, FL: Chapman and Hall/CRC. ISBN 978-1-58488-165-0.
- Hardin, James; Hilbe, Joseph (2007). Generalized Linear Models and Extensions (2nd ed.). College Station: Stata Press. ISBN 978-1-59718-014-6.
Wikipedia References
- Wikipedia contributors. "Generalized linear model". Wikipedia. Wikipedia. Retrieved 17 August 2022.