Linear regression estimates how a numeric outcome changes with one or more predictors while holding the others constant. This guide covers the logic, how to read coefficients and R-squared, and how to run a model in AnalyZ Solutions.
Linear regression is a method for studying how one numeric outcome changes with other factors. It shows which factors are linked to the outcome, by how much, and what value to expect for a particular person.
The thing you want to explain, such as income, a test score or monthly spending, is called the outcome. The factors you use to explain it, such as years of education or age, are the predictors. A coefficient is the number that tells you how much the outcome changes when a predictor goes up by one unit.
Suppose you have information on 300 adults: their monthly income, years of education, age and gender. You want to know three things. How much more do people earn for each extra year of education? Do women and men earn different amounts once education and age are taken into account? And what income would you expect for a woman aged 35 with 12 years of education? Linear regression answers all three.
A correlation says whether two variables move together, but it gives no amount and cannot account for anything else. Comparing the average income of women and men ignores that the two groups may differ in education and age. Regression handles both problems. It states the effect of each factor in the outcome's own units, and it separates the factors by comparing people who are alike on all the others.
Use linear regression when the outcome is numeric and roughly continuous, such as income, a test score, a wellbeing index, or monthly spending. Predictors can be numeric, categorical, or a mix. It suits questions like which factors are associated with higher scores, how large the gap between groups is after accounting for other differences, and how much of the variation the predictors explain together.
For yes or no outcomes, use logistic regression. For counts, use Poisson or negative binomial regression. For ordered categories, use ordinal regression. For people nested in groups, use multilevel regression.
Linear regression rests on three ideas: a straight line, the two numbers that describe it, and the gap between the line and real data. To keep the arithmetic visible, this section and the worked calculation below use six people. The results shown later use a larger set of 300.
A straight line is described by two numbers. The intercept is where the line starts, meaning the predicted outcome when the predictor is zero. The slope is how steeply it rises, meaning the change in the outcome for each one-unit increase in the predictor. For the six people, the line that fits best is:
A person with 12 years of education is predicted to earn 680 + 160 × 12 = 2,600. Each extra year adds 160. The intercept of 680 describes someone with no education at all, which lies outside the range of the data. Treat it as the starting point of the line and not as a real prediction.
Real people do not fall exactly on the line. The gap between what a person actually earns and what the line predicts is the residual. The part of the outcome that the predictors do not explain is called the error. Regression looks for the line that makes these gaps as small as possible overall.
A model can use several predictors at once, with one slope for each. A slope is also called a coefficient.
Each slope is the effect of one predictor among people who are the same on the others. A category such as gender is entered as a comparison with a chosen reference group, so its slope is the difference between the groups. The next section writes the model in symbols and shows how the best line is found.
The building blocks above combine into one equation: the outcome is a baseline plus a contribution from each predictor, plus whatever the predictors fail to explain.
The intercept b0 is the predicted outcome when every predictor is zero. Each coefficient b is the change in the predicted outcome for a one-unit increase in that predictor, holding the others constant. The error is the part of each person's outcome that the predictors cannot account for.
The method of least squares chooses the coefficients that make the sum of the squared residuals as small as possible, where a residual is the gap between a person's observed outcome and the value the line predicts. Squaring stops positive and negative gaps from cancelling out and gives large misses extra weight. With one predictor there are direct formulas:
With several predictors the principle is the same, and software solves for all the coefficients at once using matrix algebra.
| Person | Education (x) | Income (y) | x - x-bar | y - y-bar | Product | Predicted | Residual |
|---|---|---|---|---|---|---|---|
| 1 | 8 | 1,900 | -4 | -700 | +2,800 | 1,960 | -60 |
| 2 | 10 | 2,400 | -2 | -200 | +400 | 2,280 | +120 |
| 3 | 12 | 2,300 | +0 | -300 | -0 | 2,600 | -300 |
| 4 | 12 | 2,900 | +0 | +300 | +0 | 2,600 | +300 |
| 5 | 14 | 2,800 | +2 | +200 | +400 | 2,920 | -120 |
| 6 | 16 | 3,300 | +4 | +700 | +2,800 | 3,240 | +60 |
Here n is the number of cases and k the number of predictors. Adjusted R² penalises predictors that add little. The F test asks whether the predictors together explain more than chance would. For the three-predictor income model in the results below, with n = 300 and R² = 0.245, F = (0.245 ÷ 3) ÷ (0.755 ÷ 296) = 32.08, which matches the table.
Once the coefficients are known, a prediction is just arithmetic. With the model in the results below, a woman with 12 years of education aged 35 is predicted to earn:
Predictions are only trustworthy within the range of the data used to fit the model.
Each predictor has a coefficient, labelled B. For a numeric predictor, B is the expected change in the outcome for a one-unit increase in that predictor, holding the others constant. If B for years of schooling is 42, each extra year goes with 42 more units of monthly income, on average, among people who are otherwise similar.
For a categorical predictor, B compares a category with the reference category. If the reference is Male and B for Female is -35, women earn 35 units less than men on average, after accounting for the other predictors.
The table also gives a standard error, a test statistic, a significance level, and a 95% confidence interval for each coefficient. An interval that includes zero corresponds to a coefficient that is not significant at the 5% level.
R-squared is the share of the variation in the outcome that the model explains. AnalyZ Solutions reads it as weak below 10%, modest from 10% to 25%, moderate from 25% to 50%, and strong above 50%. Social research often produces modest values, since human outcomes are shaped by many things a survey does not capture. Adjusted R-squared penalises the addition of predictors that contribute little, and is the better figure when comparing models with different numbers of predictors.
The F test asks whether the predictors together explain more than chance would. It is reported with its significance level. A significant model can still have a low R-squared, which just means real but modest predictive power.
A roughly linear relationship between each numeric predictor and the outcome. Plot them to check.
Independent observations. People sampled in clusters, or measured repeatedly, violate this. Use multilevel regression for such data.
Roughly constant spread of the outcome across the range of predictions.
Approximately normal residuals, which matters mainly in small samples.
Predictors that are not almost duplicates of each other. When two predictors are extremely highly correlated, the model cannot separate their effects, and coefficients become unstable. Check the correlation matrix before including both.
A useful rule of thumb is to have at least 10 to 15 observations for each predictor in the model.
Open Inferential Analysis, choose Regression, then Linear Regression.
Running a linear regression in AnalyZ Solutions.
You can export the tables as CSV, Excel, or Word, send the results to Sense Making, or add the coefficient plot to a Data Canvas slide.
The figures below are invented to show the steps, and they follow the results tables in AnalyZ Solutions, with a few columns left out to save space. Suppose monthly income is modelled from years of education, age, and gender (reference category: Male) for 300 people.
| N | R² | Adj R² | F(3,296) | p-value | AIC |
|---|---|---|---|---|---|
| 300 | 0.245 | 0.238 | 32.08 | < 0.001 | 4066.85 |
| Variable | B | SE | t | p-value | Sig | 95% CI lower | 95% CI upper |
|---|---|---|---|---|---|---|---|
| (Intercept) | 578.59 | 71.86 | 8.051 | < 0.001 | *** | 437.16 | 720.02 |
| Years of education | 42.99 | 4.60 | 9.342 | < 0.001 | *** | 33.93 | 52.04 |
| Age | 3.63 | 1.28 | 2.834 | 0.0049 | ** | 1.11 | 6.16 |
| Gender: Female (ref: Male) | -30.52 | 24.43 | -1.249 | 0.2127 | ns | -78.60 | 17.57 |
Education was the strongest predictor of income. Each extra year was associated with about 43 more units, controlling for age and gender, and the model explained about 25% of the variation. Age had a small positive association. Gender showed no clear difference once the other variables were accounted for. These are associations after adjustment, and they do not show that extra education causes higher income.
Reading coefficients as causal effects. Regression describes association after adjustment. Causal claims need a design that supports them.
Comparing coefficient sizes across differently scaled predictors. A coefficient for income in thousands cannot be compared directly with one for age in years.
Ignoring the reference category. Every categorical coefficient is a comparison with the reference group, so choose it deliberately and state it.
Overfitting with too many predictors. Small samples with many predictors give unreliable coefficients.
Extrapolating. The model describes the range of your data. Predictions far outside it are guesses.
Open Regression in AnalyZ Solutions. Free to sign up, free to analyze.
Get started