Proba ML
12. Generalized Linear Models
12.2 Examples

12.2 Examples

12.2.1 Linear regression

The linear regression has the form:

logp(ynxn,w,σ2)=(ynηn)22σ212log(2πσ2)=ynηnηn22σ212(yn2σ2log(2πσ2))\begin{align} \log p(y_n|\bold{x}_n,\bold{w},\sigma^2)&=-\frac{(y_n-\eta_n)^2}{2\sigma^2}-\frac{1}{2}\log (2\pi \sigma^2) \\ &= \frac{y_n\eta_n-\frac{\eta_n^2}{2}}{\sigma^2}-\frac{1}{2}\Big(\frac{y_n^2}{\sigma^2}-\log(2\pi\sigma^2)\Big) \end{align}

where ηn=wxn\eta_n=\bold{w}^\top \bold{x}_n, and we see that A(ηn)=ηn2/2A(\eta_n)=\eta^2_n/2

Hence:

E[yn]=ηn=wxnV[yn]=σ2\begin{align} \mathbb{E}[y_n]&=\eta_n=\bold{w}^\top \bold{x}_n \\ \mathbb{V}[y_n]&=\sigma^2 \end{align}

12.2.2 Binomial regression

If the response variable is the number of success in NnN_n trials, yn{0,,Nn}y_n\in\{0,\dots,N_n\} we can use the binomial regression:

p(ynxn,w,Nn)=Bin(ynσ(wxn),Nn)p(y_n|\bold{x}_n,\bold{w},N_n)=\mathrm{Bin}(y_n|\sigma(\bold{w}^\top \bold{x}_n),N_n)

We see that binary logistic regression is the special case when Nn=1N_n=1.

The log pdf is:

logp(yx,w,Nn)=ynlogμn+(Nnyn)log(1μn)+log(Nnyn)=ynlogμn1μn+Nnlog(1μn)+log(Nnyn)\begin{align} \log p(y|\bold{x},\bold{w},N_n)&=y_n\log \mu_n + (N_n-y_n)\log (1-\mu_n)+\log \binom{N_n}{y_n} \\ &= y_n \log\frac{\mu_n}{1-\mu_n} + N_n\log (1-\mu_n)+\log \binom{N_n}{y_n} \end{align}

where μn=σ(ηn)\mu_n=\sigma(\eta_n), and ηn=μn1μn\eta_n=\frac{\mu_n}{1-\mu_n}

We rewrite this in GLM form:

logp(yxn,w,Nn)=ynηnA(ηn)+h(yn)\log p(y|\bold{x}_n,\bold{w},N_n)=y_n \eta_n-A(\eta_n)+h(y_n)

with A(ηn)=Nnlog(1μn)=Nnlog(1+eηn)A(\eta_n)=-N_n\log(1-\mu_n)= N_n \log (1+e^{\eta_n})

Hence:

E[yn]=dAdηn=Nneηn1+eηn=Nn1+eηn=NnμnV[yn]=d2Adηn2=Nnμn(1μn)\begin{align} \mathbb{E}[y_n]&=\frac{d A}{d\eta_n}=\frac{N_n e^{\eta_n}}{1+e^{\eta_n}}=\frac{N_n}{1+e^{-\eta_n}}=N_n \mu_n \\ \mathbb{V}[y_n]&= \frac{d^2A}{d\eta_n^2}=N_n\mu_n(1-\mu_n) \end{align}

12.2.3 Poisson regression

If the response variable is an integer count, yn{0,1,}y_n\in\{0,1,\dots\}, we can use the Poisson regression:

p(ynxn,w)=Poi(ynexp(wxn))p(y_n|\bold{x}_n,\bold{w})=\mathrm{Poi}(y_n|\exp(\bold{w}^\top \bold{x}_n))

where:

Poi(yμ)=eμμyy!\mathrm{Poi}(y|\mu)=e^{-\mu }\frac{\mu^y}{y!}

The Poisson distribution is highly used in bio-stats application, where yny_n might represent the number of diseases at a given place.

The log pdf is:

logp(ynxn,w)=ynlogμnμn+logyn=ynηnA(ηn)+h(yn)\begin{align} \log p(y_n|\bold{x}_n,\bold{w})&=y_n \log \mu_n-\mu_n+\log y_n \\ &= y_n \eta_n -A(\eta_n)+h(y_n) \end{align}

where μn=exp(ηn)=exp(wx)\mu_n=\exp(\eta_n)=\exp(\bold{w}^\top \bold{x}), and A(ηn)=μnA(\eta_n)= \mu_n

Hence:

E[yn]=dAdηn=exp(ηn)=μnV[yn]=d2Adηn2=exp(ηn)=μn\begin{align} \mathbb{E}[y_n]&=\frac{d A} {d\eta_n}=\exp(\eta_n)=\mu_n\\ \mathbb{V}[y_n]&= \frac{d^2A}{d\eta_n^2}=\exp(\eta_n)=\mu_n \end{align}