Linear/multiple/logistic regression

Linear/multiple/logistic regression

Regression fits an equation linking a response to one or more predictors, for continuous outcomes (linear, multiple) or yes/no outcomes (logistic).

What it is

Regression is a family of statistical methods that model how a response variable (the outcome you measure) depends on one or more predictor variables (the factors you set or record). It answers questions such as “how much does yield change per degree of temperature?” or “how does the probability of failure rise with load?”

The fitted model is an equation you can use to quantify effects, test whether they are distinguishable from noise, and predict new cases. Simple linear regression uses one predictor; multiple linear regression uses several at once; logistic regression handles a binary outcome such as pass/fail or infected/uninfected. Regression underpins calibration curves, materials testing, epidemiology, process engineering, economics and much of machine learning.

Fundamentals

The linear model

Simple linear regression assumes a straight-line relationship plus random scatter:

y = β0 + β1x + ε

Here y is the response, x the predictor, β0 the intercept (the value of y when x = 0), β1 the slope (the change in y per unit change in x) and ε the random error, the scatter of real points about the line.

The usual fitting method, ordinary least squares (OLS), chooses the coefficient estimates that minimize the sum of squared residuals, Σ(yi − ŷi)2, where yi is an observed value, ŷi the value predicted by the line, and their difference is the residual.

Multiple regression

y = β0 + β1x1 + β2x2 + … + βkxk + ε

With k predictors, each coefficient βj is the change in y for a one-unit change in xj with all other predictors held constant. “Linear” means linear in the coefficients, so terms such as x2 or x1x2 (an interaction) are allowed. Categorical predictors enter as dummy variables coded 0 or 1.

Fit is often summarized by R2, the fraction of the variance in y explained by the model (0 to 1). Adding a predictor never lowers R2, so adjusted R2 penalizes extra terms. Standard OLS inference assumes residuals that are independent, have constant variance (homoscedasticity) and are roughly normal, and a correctly specified relationship. Strongly correlated predictors (multicollinearity) make individual coefficients unstable.

Logistic regression

When y is binary (0 or 1), a straight line can predict impossible probabilities below 0 or above 1. Logistic regression instead models the log-odds:

ln[p / (1 − p)] = β0 + β1x1 + … + βkxk

Here p is the probability that y = 1 and p/(1 − p) is the odds. Rearranged, p = 1 / (1 + e−(β0 + β1x1 + …)), an S-shaped curve bounded by 0 and 1. Each βj is the change in log-odds per unit of xj, and eβj is the odds ratio. Coefficients are estimated by maximum likelihood, solved iteratively, not by least squares.

Simple linear Multiple linear Logistic
Response Continuous Continuous Binary (0/1)
Predictors One Two or more One or more
Fitting Least squares Least squares Maximum likelihood
Coefficient means Slope Slope, others held constant Change in log-odds
Typical fit summary R2 Adjusted R2 Deviance, AIC

Basic operation

Regression is run in software: R, Python (statsmodels or scikit-learn), MATLAB, Minitab, or a spreadsheet for simple cases. Most of the work is preparing data and choosing the model before you press “fit”.

  1. Define the question. Decide which variable is the response and which are predictors, and whether the response is continuous or binary. That choice selects linear or logistic regression.
  2. Assemble the data. One row per observation, one column per variable. Plan for enough observations: a common rule of thumb is at least 10–20 per predictor for linear models, and at least about 10 occurrences of the rarer outcome per predictor for logistic models.
  3. Explore. Plot y against each x (scatterplots, or boxplots when y is binary). Look for curvature, outliers, data-entry errors and strong correlation among predictors.
  4. Prepare variables. Code categorical predictors as dummies, consider a log transform for skewed variables or curved relationships, and center predictors if you include interaction or squared terms.
  5. Specify and fit. In R, for example, lm(y ~ x1 + x2, data = d) fits a linear model and glm(y ~ x1 + x2, family = binomial, data = d) a logistic one.
  6. Check the fit. For linear models, plot residuals against fitted values and make a normal Q–Q plot; look for patterns, funnel shapes and single influential points. For logistic models, watch for convergence or “perfect separation” warnings.
  7. Read the output. You get a coefficient table, each coefficient with its standard error, test statistic, p-value and confidence interval, plus overall statistics such as R2 and the F-test (linear) or deviance and AIC (logistic).
  8. Refine and validate. Add or remove terms on scientific grounds, not p-values alone, and where possible test predictions on data not used for fitting.

Good practice

  • Do not extrapolate beyond the range of your predictors; the relationship may change outside it.
  • In observational data a significant coefficient shows association, not that x causes y.
  • Always plot residuals. A high R2 can hide a curved relationship or one dominant outlier.
  • Check multicollinearity; variance inflation factors (VIF) above about 5–10 are a common warning sign.
  • Do not fit ordinary linear regression to a 0/1 outcome; use logistic regression.
  • Avoid overfitting: too many predictors for the data fits noise and predicts new cases poorly.

Key terms

  • Response variable — the outcome being modeled; also called the dependent variable.
  • Predictor — an input variable used to explain the response; also called an independent variable or covariate.
  • Residual — an observed value minus the value the model predicts.
  • Least squares — fitting by minimizing the sum of squared residuals.
  • R2 — the proportion of variance in the response explained by the model.
  • Odds ratio — the factor by which the odds of the outcome multiply per unit increase in a predictor.
  • Maximum likelihood — estimation that picks the parameter values making the observed data most probable.

Video coming soon

About five minutes on Linear/multiple/logistic regression: how it works in detail, how the data is acquired, and how it is analyzed.

Shopping cart

0
image/svg+xml

No products in the cart.

Continue Shopping