Quick answers
- What is the difference between correlation and regression?
- Correlation gives one number, r, for the strength and direction of a linear relationship, treating both variables alike. Regression fits an equation that predicts a response (y) from an explanatory variable (x).
- What does the correlation coefficient r mean?
- r runs from −1 to +1. Values near +1 mean both rise together, near −1 that one falls as the other rises, near 0 no linear relationship. It says nothing about cause.
- When should I use Spearman instead of Pearson correlation?
- Use Spearman's rank correlation when the data are ranks or scores, strongly skewed, have outliers, or the relationship is monotonic but not straight.
- What does R² mean?
- The proportion of the variation in y explained by the model. R² = 0.36 means start weight explains 36% of the differences in daily gain between pigs.
- What are the assumptions of linear regression?
- A straight-line relationship, independent observations, residuals with constant variance, and roughly normal residuals. Check them with residual plots.
- What is multiple linear regression?
- Regression with two or more explanatory variables. Each slope is the change in y per unit of that variable with the others held constant.
On this page
Pearson correlation
The Pearson correlation coefficient r measures the strength of a linear relationship between two continuous variables. It is the covariance scaled by both standard deviations, so it has no units:
r = Σ(x − x̄)(y − ȳ) / √[Σ(x − x̄)² × Σ(y − ȳ)²]
To test H₀: ρ = 0, use t = r √(n − 2) / √(1 − r²) with n − 2 degrees of freedom. For start weight, t = 0.60 × √22 / √(1 − 0.36) = 3.50, p = 0.002.
- Always plot first: r = 0 can hide a strong curved relationship, and one outlier can create or destroy a correlation.
- Correlation is not causation. Both variables may depend on a third, such as litter or age.
- A partial correlation removes the effect of a third variable: the link between milk fat and protein after allowing for milk yield, or between weight and height after allowing for age.
Spearman and Kendall rank correlation
Spearman's rho is the Pearson correlation of the ranks. It measures any monotonic relationship (consistently increasing or decreasing) and is not thrown off by outliers or skew. Kendall's tau is another rank measure, based on how many pairs are in the same order; it handles ties and small samples well.
Use rank correlations for scores (disease ratings, body condition), for strongly skewed data, or when you only care whether the order agrees.
Simple linear regression
Regression describes y as a straight-line function of x, plus random error:
y = β₀ + β₁x + ε
β₀ is the intercept (y when x = 0) and β₁ the slope (the change in y for one unit of x). Least squares picks the line that makes the sum of squared vertical distances from the points, the residuals, as small as possible.
The intercept here (a 0 kg pig) has no biological meaning: never predict far outside the range of x you measured, here 20 to 32 kg. In simple regression, R² is the square of r: 0.60² = 0.36.
Assumptions and residual checks
- Linearity: the mean of y changes in a straight line with x. A curved residual pattern says otherwise; see quadratic and curvilinear regression.
- Independence: each observation comes from a separate unit. Repeated weights of the same pig are not independent; see repeated measures.
- Constant variance: residuals spread evenly across fitted values, not in a funnel.
- Normal residuals: roughly, for tests and intervals. Check with a Q-Q plot.
Also look for influential points, single observations that pull the line: high leverage (extreme x) combined with a large residual. Cook's distance flags them.
Multiple linear regression
y = β₀ + β₁x₁ + β₂x₂ + … + ε
- Each slope is a partial effect, with the other variables held constant; it can differ greatly from the simple-regression slope.
- Highly correlated explanatory variables (multicollinearity) inflate standard errors and make slopes unstable. Check variance inflation factors; values above about 10 are a warning.
- R² always rises when you add variables; adjusted R² (0.92 here) penalizes useless ones.
- Choose variables from biology, not by trying every combination until something is significant.
Correlation or regression: which to use
| Question | Use |
|---|---|
| Do two traits vary together? (yield and protein, milk fat and protein) | Correlation |
| How much does y change per unit of x? Can I predict y? | Regression |
| One variable is set by the experimenter (N rate, dose) | Regression |
| Neither variable is a cause of the other | Correlation |
| Comparing groups (diets, varieties) | ANOVA |
| A treatment plus a continuous covariate | ANCOVA |
Correlation and regression in R and SAS
In R
cor.test(dat$adg, dat$feed_intake) # Pearson
cor.test(dat$adg, dat$feed_intake, method = "spearman")
fit <- lm(adg ~ start_wt, data = dat)
summary(fit) # slope, R²
plot(fit) # residual checks
summary(lm(adg ~ start_wt + feed_intake, data = dat)) # multiple regressionIn SAS
proc corr data=pigs pearson spearman;
var adg feed_intake start_wt;
run;
proc reg data=pigs;
model adg = start_wt;
model adg = start_wt feed_intake / vif;
run;Key takeaways
- Correlation (r) measures the strength of a linear link; regression gives an equation to predict y from x.
- Use Spearman for ranks, scores, skewed data or outliers; plot the data before trusting any r.
- R² is the share of variation explained; in simple regression it equals r².
- Check linearity, independence, constant variance and normal residuals with residual plots.
- In multiple regression each slope is a partial effect; watch for multicollinearity.
Questions people ask
What is a strong correlation?
There is no universal cut-off. In field and animal data, |r| above about 0.7 is usually called strong and below 0.3 weak, but the importance depends on the question.
Can correlation be greater than 1?
No. Values outside −1 to +1 mean a calculation error.
What is the coefficient of determination?
Another name for R²: the proportion of variation in y explained by the regression.
Does a significant slope mean a good prediction?
No. With many observations a slope can be significant while R² is small and predictions are poor. Report R² and the residual SD.
Should I force the regression through the origin?
Rarely. Even when y must be 0 at x = 0, the relationship may not be straight down to zero, and forcing it biases the slope.
Sources
- Kaps, M., and Lamberson, W. R. (2017). Biostatistics for Animal Science (3rd ed.), chapters on simple linear regression, correlation and multiple linear regression. CABI.
- Draper, N. R., and Smith, H. (1998). Applied Regression Analysis (3rd ed.). Wiley.
- Anscombe, F. J. (1973). Graphs in statistical analysis. The American Statistician, 27(1), 17–21.