
Relationships
Covered last time:

This lecture covers two fundamental statistical techniques in biology: correlation and regression analysis. Based on Chapters 16–17 from Whitlock & Schluter’s The Analysis of Biological Data (3rd edition), we’ll explore:
Note
📖 Reference
Whitlock & Schluter, Ch. 16 (Correlation) and Ch. 17 (Regression) are the core references for this entire lecture.
Correlation Analysis:
Regression Analysis:

Correlation analysis measures the strength and direction of a relationship between two numerical variables:
The Pearson correlation coefficient (r) is defined as:
\[r = \frac{\sum_{i}(X_i - \bar{X})(Y_i - \bar{Y})}{\sqrt{\sum_{i}(X_i - \bar{X})^2 \sum_{i}(Y_i - \bar{Y})^2}}\]
This can be simplified as:
\[r = \frac{\text{Covariance}(X, Y)}{s_X \cdot s_Y}\]
Where \(s_X\) and \(s_Y\) are the standard deviations of X and Y.

Nazca boobies (Sula granti) — do aggressive behaviors as a chick predict future aggressive behavior as an adult?
For a Pearson correlation coefficient (r) of 0.53372:
Tested by a t-test: \(\text{t}=\frac{r}{SE_r}\)
Pearson's product-moment correlation
data: booby_data$visits_as_nestling and booby_data$future_aggression
t = 2.9603, df = 22, p-value = 0.007229
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.1660840 0.7710999
sample estimates:
cor
0.5337225
Interpretation: the correlation coefficient of r = 0.534 suggests that Nazca boobies who experienced more visits from non-parent adults as nestlings tend to display more aggressive behavior as adults. This supports the hypothesis that early experiences influence adult behavior patterns in this species.
Standard error:
\[\text{SE}_r = \sqrt{\frac{1-r^2}{n-2}}\]
SE = 0.180
Need to be sure the relationship is not curved — see below.

Note
🔮 Predict first: We’re about to run Shapiro-Wilk on both booby variables, then look at their histograms and QQ plots. If the formal test and the visual check disagree, which would you trust more for n = 24?
As described in Section 16.3, correlation analysis has key assumptions:
Let’s check these assumptions with the booby data.
Shapiro-Wilk normality test
data: booby_data$visits_as_nestling
W = 0.95783, p-value = 0.3965
Shapiro-Wilk normality test
data: booby_data$future_aggression
W = 0.91575, p-value = 0.04709
As described in Section 16.3, correlation analysis has key assumptions:
Let’s check these assumptions using the booby data.

Tip
🖐 Notice
The lion nose-pigmentation data (used here just as an example of non-normal data) shows a right-skewed proportion_black and clearly non-normal QQ plots — this is exactly when Spearman’s is the better tool.

To understand the amount of variation explained, you can square the non-parametric Spearman’s rho value.
For your value of 0.74485:
\[\rho^2 = 0.74485^2 = 0.5548\]
This means approximately 55.48% of the variance in the ranks of one variable can be explained by the ranks of the other. This is similar to how R² works in linear regression, but specifically for ranked data.
Spearman's rank correlation rho
data: lion_data$proportion_black and lion_data$age_years
S = 1392.1, p-value = 1.013e-06
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho
0.7448561

Simple linear regression models the relationship between a response variable (Y) and a predictor variable (X).
The population regression model: \(Y = \alpha + \beta X + \varepsilon\)
The sample regression equation: \(\hat{Y} = a + bX\)
Method of least squares: the line is chosen to minimize the sum of squared vertical distances (residuals) between observed and predicted Y values.
Note
📖 Reference
Whitlock & Schluter, Ch. 17 — Regression, is the primary reference for the rest of this lecture.

Simple linear regression models the relationship between a response variable (Y) and a predictor variable (X).
The population regression model: \(Y = \alpha + \beta X + \varepsilon\)
The sample regression equation: \(\hat{Y} = a + bX\)
Method of least squares: the line is chosen to minimize the sum of squared vertical distances (residuals) between observed and predicted Y values.

From Example 17.1 in the textbook, the regression line for the lion data is:
\[\text{age} = 0.88 + 10.65 \times \text{proportion}_{black}\]
This means:

Call:
lm(formula = age_years ~ proportion_black, data = lion_data)
Residuals:
Min 1Q Median 3Q Max
-2.5449 -1.1117 -0.5285 0.9635 4.3421
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.8790 0.5688 1.545 0.133
proportion_black 10.6471 1.5095 7.053 7.68e-08 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.669 on 30 degrees of freedom
Multiple R-squared: 0.6238, Adjusted R-squared: 0.6113
F-statistic: 49.75 on 1 and 30 DF, p-value: 7.677e-08
The calculation for slope (m) is:
\[m = \frac{\sum_i(X_i - \bar{X})(Y_i - \bar{Y})}{\sum_i(X_i - \bar{X})^2}\]
Given:
b = 13.0123 / 1.2221 = 10.647
Intercept: \(b = \bar{Y} - m\bar{X} = 4.3094 - 10.647(0.3222) = 0.879\)

To predict the age of a lion with 0.50 proportion of black on its nose:
\[\hat{Y} = 0.88 + 10.65(0.50) = 6.2 \text{ years}\]
Confidence intervals vs. prediction intervals:
Both intervals are narrowest near \(\bar{X}\) and widen as X moves away from the mean.

Call:
lm(formula = log_stability ~ species_number, data = prairie_data)
Residuals:
Min 1Q Median 3Q Max
-0.82774 -0.25344 -0.00426 0.27498 0.75240
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.252629 0.041023 30.535 < 2e-16 ***
species_number 0.025984 0.004926 5.275 4.28e-07 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.3433 on 159 degrees of freedom
Multiple R-squared: 0.149, Adjusted R-squared: 0.1436
F-statistic: 27.83 on 1 and 159 DF, p-value: 4.276e-07
Analysis of Variance Table
Response: log_stability
Df Sum Sq Mean Sq F value Pr(>F)
species_number 1 3.2792 3.2792 27.829 4.276e-07 ***
Residuals 159 18.7358 0.1178
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The hypothesis test asks whether the slope equals zero:
t = estimate / SE
Interpretation:
The slope estimate is 0.033, indicating that log stability increases by 0.033 units for each additional plant species in the plot.
The p-value is very small (2.73e-10), providing strong evidence to reject the null hypothesis that species number has no effect on ecosystem stability.
R² = 0.222, meaning approximately 22.2% of the variation in log stability is explained by the number of plant species.
This supports the biodiversity-stability hypothesis: more diverse plant communities have more stable biomass production over time.

Linear regression has four key assumptions:
Let’s check these assumptions for the lion regression model.
Assume that error \(\varepsilon_i\) is normally distributed for each x_i, has the same variance, and has a mean of 0 at each x_i.

Linear regression has four key assumptions: linearity, independence, homoscedasticity, and normality.
Let’s check these assumptions for the lion regression model.
The error \(\varepsilon_i\) is estimated as the residual: \(e_i = y_i - \hat{y}_i\)
Ordinary least squares estimates a and b (intercept and slope) to minimize the sum of the residuals squared:
\[\sum_{i=1}^{n} (y_i - \hat{y}_i)^2\]

Linear regression has four key assumptions: linearity, independence, homoscedasticity, and normality.
Let’s check these assumptions for the lion regression model. Linearity — how does this plot work?

Linear regression has four key assumptions: linearity, independence, homoscedasticity, and normality.
Let’s check these assumptions for the lion regression model.

Linear regression has four key assumptions: linearity, independence, homoscedasticity, and normality.
Let’s check these assumptions for the lion regression model.
Shapiro-Wilk normality test
data: residuals(lion_model)
W = 0.93879, p-value = 0.0692
Linear regression has four key assumptions: linearity, independence, homoscedasticity, and normality.
If assumptions are violated:


In addition to getting estimates of population parameters (β₀, β₁), we want to test hypotheses about them.
Note
📖 Reference
Gotelli & Ellison, A Primer of Ecological Statistics, Ch. 9 — Regression, covers this variance-partitioning approach to testing a regression slope.

Total variation in Y is “partitioned” into 3 components:

Total variation in Y is “partitioned” into 3 components:

Total variation in Y is “partitioned” into 3 components:

\[SS_{regression} + SS_{residual} = SS_{total}\] \[df_{regression} + df_{residual} = df_{total}\]

Sums of squares converted to mean squares:
Note
✅ Key idea
The F-ratio in a regression ANOVA table is exactly \(MS_{regression} / MS_{residual}\) — the same logic you’ll see again when we get to ANOVA for group comparisons.
