Before you start
- You know p-values and basic distributions (see Stats you cannot avoid), and you can run basic R (see R basics).
- Any term new? The Glossary has it.
Learning objectives
By the end of this lesson you will be able to: read a simple regression as a slope and intercept, interpret a coefficient in a multiple regression, recognize that the t-test and ANOVA are special cases of a linear model, and fit and read lm() in R.
Regression is just a recipe for predicting an outcome
A regression model describes one outcome (the thing you measured, like gene expression) as a function of one or more predictors (the things you think explain it, like drug dose or genotype). It does not prove cause; it summarizes how the outcome tends to change as the predictors change.
The simplest version, simple linear regression, fits a straight line through your data. That line has just two numbers:
y = b0 + b1 × x
- b1, the slope: how much the outcome
ychanges for each one-unit increase in the predictorx. Ifb1 = 2, then y goes up by 2 for every extra unit of x. - b0, the intercept: the predicted value of
ywhenxis zero. It sets where the line crosses the vertical axis.
1Seeing the slope and intercept
Each real point sits a little above or below the line. Those gaps are the residuals. Regression chooses the slope and intercept that make those residuals as small as possible overall (the "least squares" fit).
2Multiple regression: holding the others constant
Real biology rarely has one cause. Multiple regression just adds more predictors:
y = b0 + b1×x1 + b2×x2 + ...
Now each coefficient has a precise meaning: it is that predictor's effect on the outcome holding the other predictors constant. So b1 is the change in y per unit of x1 among samples that share the same x2. This is how you adjust for a confounder such as batch, sex, or age: put it in the model, and the other coefficients describe effects beyond it.
3The big idea: your favorite tests are linear models
Here is the insight that makes everything click. Many tests you already know are special cases of one linear model, differing only in what kind of predictor you feed it.
| Familiar test | Is really a linear model with... | What the slope means |
|---|---|---|
| Two-group t-test | one binary (0/1) predictor | the difference in group means |
| One-way ANOVA | one categorical predictor (several groups) | each group's mean vs a reference group |
| ANCOVA | one categorical plus one numeric predictor | group difference adjusted for the numeric covariate |
| Pearson correlation | one numeric predictor (standardized) | the strength of the linear relationship |
When you compare two groups with a t-test, you are fitting y = b0 + b1×group where group is 0 for one group and 1 for the other. The intercept b0 is the first group's mean, and the slope b1 is exactly how much the second group differs. ANOVA is the same idea with a categorical predictor that has more than two levels. Learn the linear model once and these tests stop being separate things to memorize.
Why this matters in bioinformatics
The workhorse RNA-seq tools, DESeq2, edgeR, and limma, are all generalized linear models underneath: linear models extended to handle count data and non-normal noise. The "design formula" you write for them, such as ~ condition + batch, is exactly the predictor list of a linear model. Understanding lm() is the foundation for understanding those tools.
4Worked example: fitting lm() in R
Suppose you measured a gene's expression at several drug doses and want to know how strongly expression tracks dose. In R you fit the model and read its summary:
# expression measured across a range of doses fit <- lm(expression ~ dose) summary(fit) # Coefficients: # Estimate Std. Error t value Pr(>|t|) # (Intercept) 5.20 0.41 12.7 1.1e-06 # dose 0.85 0.12 7.1 9.3e-05 <- slope b1 # # Multiple R-squared: 0.78
How to read it:
- The dose estimate (0.85) is the slope: expression rises by about 0.85 units for every one-unit increase in dose.
- Its p-value (9.3e-05) tests whether that slope differs from zero. Small p means dose is associated with expression more than you would expect by chance.
- The (Intercept) 5.20 is the predicted expression at dose zero.
- R-squared (0.78) is the fraction of variation in expression that the model explains: here about 78 percent.
To run a t-test as a linear model instead, you would write lm(expression ~ group) with a two-level group, and the group coefficient is the difference in means.
5A quick word on assumptions
Linear models trust two things, and it is worth a glance before believing the numbers. First, that the relationship is roughly linear (a straight line is a fair summary, not a curve). Second, that the residuals are reasonably symmetric, similar in spread across the range, and not strongly patterned. A quick plot(fit) in R shows residual plots that flag obvious problems. If the relationship curves, you may need to transform a variable or use a different model.
Common trap
The intercept is only meaningful if x = 0 is a real, sensible value. For a dose that never reaches zero, the intercept is just a mathematical anchor for the line, not a quantity to interpret on its own.
Check your understanding
lm() function fits the model and summary() reports the coefficients, p-values, and R-squared.