Reading glm output in R
Section of Introduction to generalised linear models, part of Generalised linear models
Reading glm output in R
| Type | Section |
| Taught in | Introduction to generalised linear models |
| Part | Generalised linear models |
After the score equation, the program is only evaluating Equation (12) in Introduction to generalised linear models. For a binary disease column, a sex indicator, and cholesterol,
chol_file <- "data/cholest.csv"
if (!file.exists(chol_file)) {
stop("Could not find data/cholest.csv. Set the working directory to the folder that contains it.")
}
chol <- read.csv(chol_file)
fit <- glm(disease ~ gender + cholesterol, data = chol, family = binomial)
fit
fit$iterNaming binomial and not naming a link selects the logit. The coefficients printed for this fit are the ones already interpreted in Equation (10) in Introduction to generalised linear models:
Coefficients:
(Intercept) gender cholesterol
-9.3203 -0.1094 1.5842
Degrees of Freedom: 99 Total (i.e. Null); 97 Residual
Null Deviance: 137.6
Residual Deviance: 114 AIC: 120
One hundred patients and three coefficients leave 97 residual degrees of freedom. The deviance and the AIC are on this printout because the software always writes them. We will say what they measure when we come to goodness of fit. The line that belongs to the algorithm above is the iteration count: four Fisher-scoring steps.
Estimating \boldsymbol{\beta} is the less interesting half of a statistical analysis. The half that matters next is the precision of those three numbers, and the test of whether sex can be removed. That is the next chapter. The fit above is the point at which this chapter stops.
Show that the exponential density f(y;\lambda)=\lambda e^{-\lambda y}, for y>0 and \lambda>0, is an exponential family. Identify a(y), the natural parameter, and the dispersion.
Take the gamma density, with \phi fixed, written as f(y;\lambda)=\frac{y^{\phi-1}\lambda^{\phi}e^{-\lambda y}}{\Gamma(\phi)}. Here \lambda is sometimes called a scale parameter. The formula is the shape-and-rate density: \lambda is a rate, and the scale is 1/\lambda. Using the density as written, show that it is an exponential family in \lambda with \phi held fixed, and identify the natural parameter. Then match it to the mean-and-variance form used in the clotting example.
With r known, show that f(y;\theta)=\binom{y+r-1}{r-1}\theta^{r}(1-\theta)^{y}, \qquad y=0,1,2,\ldots, is an exponential family in \theta. State the natural statistic and the natural parameter. (This is a negative binomial: the number of failures before r successes.)
Repeat the differentiation in the proof of Note for the general form Equation (6) in Introduction to generalised linear models, in which a(y) and b(\theta) need not be the identity. The mean is no longer -c'(\theta).
Show that Equation (9) in Introduction to generalised linear models maps every real linear predictor to a probability in (0,1).
Starting from the Poisson log-likelihood, and then from the gamma log-likelihood in the mean-and-variance parameterisation, show that the score equation for \boldsymbol{\beta} has the form Equation (11) in Introduction to generalised linear models.
Used in
See also
Exponential family · Mean and variance of an exponential family · Generalised linear model · Canonical link · What a regression statement is hiding · Three examples the linear model does not fit · Runs in the past week · Clotting-time data