The interpretation of coefficients in (generalized) linear models is more subtle than you many realise, and has consequences for how we test hypotheses and report findings. We will start by talking about marginal vs. conditional interpretations of model parameters.
In this example, we model plant height as a function of altitude and temperature. These variables are negatively correlated: it is colder the higher you go. We start by simulating some data to reflect this.
library(mvtnorm)# Specify the sample sizeN<-1000# Specify the correlation between altitude and temperaturerho<--0.4# This line of code creates two correlated variablesX<-rmvnorm(N, mean =c(0, 0), sigma =matrix(c(1, rho, rho, 1), 2, 2))# Extract the first and second columns to vectors named temp and alt and plottemp<-X[, 1]alt<-X[, 2]plot(temp, alt)
Now we can simulate some data for height of plants. Here we say that the mean height of plants is 2 (when all the other variables are 0), as temperature increases by one unit (holding altitude constant), the mean of height will increase by 1 unit (beta[2] = 1), and similarly as you increase altitude by 1 unit (holding temperature constant) then mean height decreases by 1 (beta[3] = -1). Height is then normally distributed with this mean and standard deviation of 2.
The interpretation of these coefficients is that if you hold everything else in the model constant (i.e., temperature) and add 1 to altitude, then the estimated mean height will decrease by 0.9. Note that the coefficient depends on the units in which altitude is measured. If altitude is in meters then the coefficient tells you what happens when you go up 1 meter.
The intercept is the predicted value when all the other variables are set to 0, which sometimes makes sense (here it would be the height of plants at sea level and 0 temperature). Other times 0 is not a meaningful value, and if you would like to interpret the intercept it might make sense to rescale your other variables so that their mean is 0. If you do this, then the intercept is the predicted value when all other variables are at their mean level.
The coefficient of temperature is now 1.44, what’s going on? Altitude is an important predictor of plant height, and some of the information about altitude is contained in temperature (remember they are correlated, so as altitude increases temperature decreases). The model accounts for this by changing the effect of temperature to take account of the information it contains about altitude. Notice the coefficient of temperature is wrong by approximately 0.4, the amount of correlation between the variables.
Note: When statisticians talk about this, they use the words conditional and marginal. Conditional is the effect of a variable when others are held constant (as in lm_both), while marginal is the overall effect (as in lm1). Note: If you use the code above to simulate your own data sets, you will get slightly different values for the coefficients.
18.1 Testing hypotheses
This distinction has a lot of consequences for modelling as well as testing hypothesis. Let’s generate some data where altitude predicts height, and temperature has no (additional) information, and then test for temperature.
Analysis of Variance Table
Response: height
Df Sum Sq Mean Sq F value Pr(>F)
temp 1 265.9 265.87 52.646 8.013e-13 ***
Residuals 998 5040.0 5.05
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The output of this model is telling us there is an effect of temperature, even though technically there isn’t. It is not giving us false information if you understand how to interpret model outputs. Because temperature is correlated with altitude, and there is an effect of altitude, when altitude is not in the model, the model tells us overall there is an effect of temperature of increasing height by 0.48 (remember the correlation was 0.4). If our hypothesis is ‘Does plant height change with temperature?’, the answer is yes, the higher the temperature, the taller the plants.
But what about altitude? We know the temperature effect we observe is because it is correlated with altitude, temperature does not directly predict height. If we want to know if there is an effect of temperature after controlling for altitude (holding altitude constant, so conditional), then we fit the model with altitude and then test for temperature.
Analysis of Variance Table
Response: height
Df Sum Sq Mean Sq F value Pr(>F)
alt 1 995.1 995.09 230.9971 < 2e-16 ***
temp 1 15.9 15.87 3.6834 0.05524 .
Residuals 997 4294.9 4.31
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The p-value is 0.0552, which is above 0.05. At the 5% significance level, we do not reject the null hypothesis of no temperature effect after controlling for altitude.
Note: The distinction between conditional and marginal interpretations is also true for generalised linear models and mixed models.
18.2 Categorical covariates
When we have categorical covariates (for example treatment), there are a number of ways to code the model, which will give different interpretations for the coefficients. Let’s simulate 120 data points with 40 in each of three levels of a categorical treatment.
N<-120# The effect of treatmenttrt.n<-rep(c(-1, 0, 1), N/3)mu<-2+1*trt.n# Labels for the treatmenttreatment<-factor(rep(c("low", "med", "high"), N/3))# group labels# Create, Y, a normally distributed response variable and plot against treatmentY<-rnorm(N, mu, sd =2)boxplot(Y~treatment)
If we put treatment in as a covariate the normal way, the model will choose a reference treatment (here it will be high as the levels get sorted alphabetically), so that the intercept will be the mean of this reference group. The other coefficients will be the differences between the other groups and the reference group.
Call:
lm(formula = Y ~ treatment)
Residuals:
Min 1Q Median 3Q Max
-5.473 -1.274 0.003 1.306 4.746
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.8372 0.3155 8.991 5.13e-15 ***
treatmentlow -1.8454 0.4462 -4.135 6.70e-05 ***
treatmentmed -0.9669 0.4462 -2.167 0.0323 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.996 on 117 degrees of freedom
Multiple R-squared: 0.1276, Adjusted R-squared: 0.1127
F-statistic: 8.557 on 2 and 117 DF, p-value: 0.00034
So here group “high” has a mean of 2.84, and the difference between the means of group “low” and group “high” is -1.85, and the difference between group “med” and group “high” is -0.97. If you would like to have another group as the reference group, you can use relevel to recode your treatment factor.
Now the intercept is the mean of group “low”, and all the other coefficients are the differences between group “low” and the others. Another thing you can do is to put -1 in the model to get rid of the intercept, and just have the means of each group as coefficients.
Call:
lm(formula = Y ~ treatment - 1)
Residuals:
Min 1Q Median 3Q Max
-5.473 -1.274 0.003 1.306 4.746
Coefficients:
Estimate Std. Error t value Pr(>|t|)
treatmentlow 0.9918 0.3155 3.143 0.00212 **
treatmenthigh 2.8372 0.3155 8.991 5.13e-15 ***
treatmentmed 1.8703 0.3155 5.927 3.18e-08 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.996 on 117 degrees of freedom
Multiple R-squared: 0.5182, Adjusted R-squared: 0.5059
F-statistic: 41.95 on 3 and 117 DF, p-value: < 2.2e-16
Now, the three coefficients are the mean of the groups.
Contrasting the coefficients We can also look at contrasts; these are the difference between all pairs of groups. Load the package multcomp and use glht (general linear hypotheses) to examine all pair-wise differences.
Simultaneous Tests for General Linear Hypotheses
Multiple Comparisons of Means: Tukey Contrasts
Fit: lm(formula = Y ~ treatment - 1)
Linear Hypotheses:
Estimate Std. Error t value Pr(>|t|)
high - low == 0 1.8454 0.4462 4.135 0.000219 ***
med - low == 0 0.8785 0.4462 1.969 0.124585
med - high == 0 -0.9669 0.4462 -2.167 0.081192 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Adjusted p values reported -- single-step method)
Each line of this output compares two groups against one another. The first line, for example, compares the “high” group to the “low” group. So the difference between the means of the “high” and “low” groups is 1.85. The p-values and the confidence intervals given byglht control for multiple testing, which is handy. If you want to see the confidence intervals for the differences between the groups.
Simultaneous Confidence Intervals
Multiple Comparisons of Means: Tukey Contrasts
Fit: lm(formula = Y ~ treatment - 1)
Quantile = 2.3742
95% family-wise confidence level
Linear Hypotheses:
Estimate lwr upr
high - low == 0 1.84542 0.78596 2.90489
med - low == 0 0.87851 -0.18096 1.93797
med - high == 0 -0.96692 -2.02638 0.09255
Note: In a model with multiple covariates, the same rules still apply in terms of conditional and marginal interpretations of coefficients.
Interpreting coefficients in generalised linear models In linear models, the interpretation of model parameters is linear, as discussed above. For generalised linear models, now read the tutorial page on interpreting coefficients in those models.