Statistical modeling : Generalised Linear model
Logistic models
2025-07-07
GLM theory suggests that the canonical link can be modeled as a linear combination of the explanatory variable(s). This approach unifies a number of modeling results used in statistics. By so doing we have now generalized our modeling to handle non-normal responses. In addition to normally distributed responses, we are able to handle Poisson responses, binomial responses, and more. Writing a pmf or pdf for a response in one-parameter exponential family form reveals the canonical link which can be modeled as a linear function of the predictors.
Exponential Family
The theory of GLMs is developed for data with distribution given y belongs to the exponential family.
The form of the data distribution that is useful for GLMs is
\[ f(y;\theta, \phi) = \exp(\frac{\theta y - b(\theta)}{a(\phi)} + c(y, \phi)) \]
where
- \(\theta\) is called the natural parameter
- \(\phi\) is called the dispersion parameter
Example
if we have \(Y \sim N(\mu, \sigma^2)\)
\[ \begin{aligned} f(y; \mu, \sigma^2) &= \frac{1}{(2\pi \sigma^2)^{1/2}}\exp(-\frac{1}{2\sigma^2}(y- \mu)^2) \\ &= \exp(-\frac{1}{2\sigma^2}(y^2 - 2y \mu +\mu^2)- \frac{1}{2}\log(2\pi \sigma^2)) \\ &= \exp(\frac{y \mu - \mu^2/2}{\sigma^2} - \frac{y^2}{2\sigma^2} - \frac{1}{2}\log(2\pi \sigma^2)) \\ &= \exp(\frac{\theta y - b(\theta)}{a(\phi)} + c(y , \phi)) \end{aligned} \]
where
- \(\theta = \mu\)
- \(b(\theta) = \frac{\mu^2}{2}\)
- \(a(\phi) = \sigma^2 = \phi\)
- \(c(y , \phi) = - \frac{1}{2}(\frac{y^2}{\phi}+\log(2\pi \sigma^2))\)
Properties of GLM exponential families
\(E(Y) = b' (\theta)\) where \(b'(\theta) = \frac{\partial b(\theta)}{\partial \theta}\)
\(var(Y) = a(\phi)b''(\theta)= a(\phi)V(\mu)\).
- \(V(\mu)\) is the variance function; however, it is only the variance in the case that \(a(\phi) =1\)
If \(a(), b(), c()\) are identifiable, we will derive expected value and variance of Y.
Examples
Normal distribution
\[ \begin{aligned} b'(\theta) &= \frac{\partial b(\mu^2/2)}{\partial \mu} = \mu \\ V(\mu) &= \frac{\partial^2 (\mu^2/2)}{\partial \mu^2} = 1 \\ &\to var(Y) = a(\phi) = \sigma^2 \end{aligned} \]
Poisson distribution
\[ \begin{aligned} f(y, \theta, \phi) &= \frac{\mu^y \exp(-\mu)}{y!} \\ &= \exp(y\log(\mu) - \mu - \log(y!)) \\ &= \exp(y\theta - \exp(\theta) - \log(y!)) \end{aligned} \]
where
- \(\theta = \log(\mu)\)
- \(a(\phi) = 1\)
- \(b(\theta) = \exp(\theta)\)
- \(c(y, \phi) = \log(y!)\)
Hence,
\[ \begin{aligned} E(Y) &= \frac{\partial b(\theta)}{\partial \theta} = \exp(\theta) = \mu \\ var(Y) &= \frac{\partial^2 b(\theta)}{\partial \theta^2} = \mu \end{aligned} \]
Since \(\mu = E(Y) = b'(\theta)\)
In GLM, we take some monotone function (typically nonlinear) of \(\mu\) to be linear in the set of covariates
\[ g(\mu) = g(b'(\theta)) = \mathbf{x'\beta} \]
Equivalently,
\[ \mu = g^{-1}(\mathbf{x'\beta}) \]
where \(g(.)\) is the link function since it links mean response (\(\mu = E(Y)\)) and a linear expression of the covariates
Application in R
Data Dictionery
Fit a simple logistic regression model using age as the only risk factor of heart disease status
A logistic regression model is a generalized linear model and is made of a linear predictor:
\[\underbrace{g(\mu_i)}_{Link~~function} = \underbrace{\beta_0 + \beta_1X_1~+~...~+~\beta_pX_p}_{Linear~component}\]
Modeling in R
To fit a logistic model in R we use the function:
model <- glm(y~x, data, family = "binomial", ...)
summary(model)Simple Logistic in R
- the equation below shows a simple logistic regression model fit on age as the predictor.
\[ \begin{aligned} \log(\frac{\mu_i}{1-\mu_i})= 2.943003-.0530036Age \end{aligned}\]
Report the estimated coefficient for age, and interpret its sign and meaning in the context of heart disease risk
- the model for the output above can be written as follows
\[ \begin{aligned} \text{logit}(\mu_i) &= \log(\frac{\mu_i}{1-\mu_i})\\ &= 2.943003-.0530036Age \end{aligned}\]
- The estimated coefficient for age is
-0.0530036and it is negative - Here we see that for a 1 year increase in age , the log odds of being diagnosed with heart disease decrease significantly by
0.0530036 - Thus the chances of developing heart disease decrease with age
Is Age significantly associated with heart disease?
- Age is indeed significantly associated with probability of developing heart disease at 5% level of significance since the corresponding p-value is 0.000 and is less than
0.05 - the coefficient’s confidence is given by \([-0.0674686 ,-0.0385386]\) and does not contain zero hence the variable is significant.
\[ \begin{aligned} \log(\frac{\mu_i}{1-\mu_i})&= 2.943003-.0530036Age\\ \frac{\mu_i}{1-\mu_i}&=e^{2.943003-.0530036Age}\\ \frac{\mu_i}{1-\mu_i}&=e^{2.943003}.e^{-.0530036Age} \end{aligned}\]
- the odds associated with age is therefore \(e^{-.0530036}=0.9483766\) meaning that for a 1 year increase in age the odds of being diagnosed with heart disease decrease by \((1-0.9483766)*100\% \approx 5.16\%\)
- also note that we can find the probability of being diagnosed at a given age by the following probability formula.
\[ \begin{aligned} \hat{p}(x) &= \frac{exp^{\hat{\beta}_{0} + \hat{\beta}_{1}{age}}}{1 + exp^{\hat{\beta}_{0} + \hat{\beta}_{1}{age}}}\\ &= \frac{exp^{2.943003-.0530036Age}}{1 + exp^{2.943003-.0530036Age}} \end{aligned}\]
likelihood ratio test in R
- The likelihood ratio test above compares the null model with a model with age alone.
- the \(p-value<0.001\) indicates that the model with age is better fit compared to a model with no covariates at all.
- thus our current model fits the data better than a model with no predictors.
Add sex variable
Model with sex in R
- the model for the output above can be written as follows
\[ \begin{aligned} \text{logit}(\mu_i) &= \log(\frac{\mu_i}{1-\mu_i})\\ &= 4.819817-.0674349Age-1.533812Male \end{aligned}\]
- The estimated coefficient for age is
-.0674349and it is negative - Here we see that for a 1 year increase in age , the log odds of being diagnosed with heart disease decrease significantly by
0.0674349while adjusting for gender of the patient. - whilst Adjusting for Age, males have
1.533812less log odds of being diagnosed with heart disease as compared to females. - the two variables are significant at 5% level of significance since they have p-values less than 5%
Since the Wald statistic follows a normal distribution with \(n\) large, we could generate a Wald-type (normal-based) confidence interval for \(\beta_2\) using:
\(\hat\beta_2 \pm 1.96\cdot\textrm{SE}(\hat\beta_2)\) and then exponentiating endpoints if we prefer a confidence interval for the odds ratio \(e^{\beta_2}\). In this case,
\[ \begin{align*} 95\% \textrm{ CI for } \beta_2 &= \hat{\beta}_2 \pm 1.96 \cdot \textrm{SE}(\hat{\beta}_2) \\ &= -1.533812 \pm 1.96 \cdot 0.158526 \\ &= -0.0132 \pm 0.00764 \\ &= (-1.223101, -1.844523) \\ 95\% \textrm{ CI for } e^{\beta_2} &= (e^{-1.223101}, e^{-1.844523}) \\ &= (0.2943161, 0.1581007) \\ \end{align*} \]
Thus, we can be 95% confident that being male is associated with a 84% to 70.7% decrease in the odds of dying after controlling age.
Comments
target(Y) and a single continuous predictorcholestrol(X). The solid line is a linear regression fit with least squares to model the probability of a success(Y=1 , presence of disease)for a given value ofcholestrolX. With a binary response, the line doesn’t fit the data well, and it produces predicted probabilities below 0 and above 1. On the other hand, the logistic regression fit (dashed curve) with its typical “S” shape follows the data closely and always produces predicted probabilities between 0 and 1.