Plain-language explanations of the model terms, output columns and diet comparisons
What are we trying to describe?
A response is the measured outcome, such as average weight gain or number of treatment events. An explanatory variable is a recorded condition used to describe differences in the expected outcome, such as diet or room.
In the class study, diet is assigned to whole pens within four rooms. Each pen contains six pigs, but one row records one pen-level outcome. There are 64 independently treated pens, not 384 independent diet assignments.
What does the formula say?
response ~ diet + room puts the outcome on the left of ~ and the explanatory variables on the right. It lets expected outcomes differ by diet and by room. It compares diets while allowing for differences between rooms.
The formula is only part of a GLM. We also state the family, which describes the response distribution after allowing for the explanatory variables, and the link, which connects its expected value to the sum of the model terms. That sum is called the linear predictor.
Outcome for one pen
Family and link used in class
How to explain the diet comparison
Average daily gain, g/day
Gaussian, identity
High fibre minus Control expected gain, in g/day
Whether any pig was treated, 0 or 1
Binomial, logit
Predicted probability for each diet; exponentiating the diet coefficient gives an odds ratio
Treatment-event count in 28 days
Poisson, log
High fibre / Control expected-count ratio
Feed conversion ratio, kg feed per kg gain
Gamma, log
High fibre / Control expected feed conversion ratio
With an identity link, the linear predictor is already the expected outcome. With a log link, use exp() to convert the linear predictor back to a positive expected value. With a logit link, use plogis() to convert it back to a probability.
How do we read the coefficient output?
Control and Room 1 are the reference categories, the starting point for the fitted comparisons. (Intercept) describes their combination on the model’s link scale. For gain with an identity link, it is expected Control gain in Room 1.
Estimate is the fitted coefficient value. dietHigh fibre compares High fibre with Control within the same room. Its units and interpretation depend on the link, as shown in the table. Std. Error describes uncertainty in the coefficient estimate; it is not the spread of individual pen observations.
Ask for predictions under stated conditions
The example below reads Group 3’s treatment counts into d, fits the supplied Poisson-log model, and asks for both diets in Room 1. source() loads the supplied functions; prediction_grid(d) lists the diet-and-room combinations, and room1 keeps the two we want here.
source("glm-helpers.R")d <-read_pen_data(3) # treatment events per penfit <-glm(response ~ diet + room, family =poisson("log"), data = d)grid <-prediction_grid(d)room1 <-subset(grid, room =="Room 1")data.frame(room1, expected_events =predict(fit, newdata = room1, type ="response"))
diet room expected_events
1 Control Room 1 2.405172
2 High fibre Room 1 1.469828
expected_events is the estimated average number of treatment events per pen over 28 days. It need not be a whole number, even though an observed count must be. Comparing the two rows tells us which diet has the higher expected count in Room 1.
In the group scripts, expected, lower and upper give an estimated average or probability and its approximate 95% confidence limits. These limits describe uncertainty in the estimate, assuming the model is appropriate. They are not prediction limits for a new pen, and they do not establish that the assumptions are correct.
Probability is different from odds
For Group 2, probability means the chance that at least one pig in a pen needed treatment. A probability of 0.30 corresponds to about 30 out of 100 comparable pens having that event.
Odds are probability / (1 - probability): here, 0.30 / 0.70. An odds ratio compares odds between diets. If the odds ratio were 0.60, multiply the Control odds by 0.60, then convert back using odds / (1 + odds). The resulting High fibre probability is about 0.205, not 0.30 * 0.60 = 0.18.
The pen-level outcome does not tell us an individual pig’s probability of treatment, or how many pigs in a pen were treated.
What does an interaction mean in the gain example?
An additive model, gain ~ diet + housing + room, requires the same High fibre minus Control gain difference in both housing conditions. Adding an interaction, using diet * housing, allows that difference to change. R includes diet, housing and diet:housing when we write diet * housing.
To explain the result, predict the four diet-and-housing averages in one room. Calculate High fibre minus Control within Standard housing and within Enriched housing. Then compare those differences, in g/day. This explanation is for the Gaussian identity-link example; under other links, the interaction concerns the comparison on that link’s scale.
Before relying on any result, check the study design, warning messages and whether the model reasonably describes the observations. We will develop those checks in Week 9.