Statistics tutorial · Chapter 07
Correlation and regression
This chapter presents the analyses that relate two or more variables: correlation (measuring the strength of an association), simple linear regression (describing and predicting Y from X with a straight line), Deming regression (comparing two measurement methods, both subject to error), multiple linear regression (several predictors, or counts with Poisson regression) and simple and multiple logistic regression (predicting a binary outcome). The fitting of nonlinear curves is the subject of the next chapter.
Two rules apply throughout the chapter. A correlation or a nonzero slope never establishes a cause-and-effect relationship: a third variable may explain the association, and only an experimental design (randomization) allows a conclusion about causality. And a P value above 0.05 does not establish the absence of an association: it only means that the data do not allow you to assert one; the confidence interval tells you which values remain compatible with the data.
Correlation#
Correlation measures how much two variables vary together. The Pearson coefficient r measures the strength of a linear relationship; the Spearman coefficient rs measures the strength of a monotonic relationship (one that always rises or always falls, without necessarily being a straight line) by working on ranks. Both range from −1 (perfect negative association) to +1 (perfect positive association); 0 means no linear association (Pearson) or no monotonic association (Spearman). Variance computes r, its confidence interval, r² and the P value of the test of the null hypothesis "zero correlation in the population", for a pair of variables or for all the pairs in a list of variables (correlation matrix).
When to use it#
- You measured two variables on each subject (weight and height, age and blood pressure...) and you want to quantify their association, without designating either one as the cause of the other.
- Both variables are random: neither is set by the experimenter. If X is controlled (chosen doses, times or concentrations), use regression: r then depends on the range of X values chosen and has no interpretation of its own.
- Choose Pearson when the relationship is roughly linear and both variables roughly follow a joint normal distribution; choose Spearman for a nonlinear monotonic relationship, for ordinal data (scores), or in the presence of extreme values.
- The correlation matrix is used to explore many variables at once, for example before a multiple regression.
- To find out whether two measurement methods agree, correlation is not suitable (two highly correlated methods can give very different values): use Bland-Altman analysis or Deming regression.
Assumptions and checks#
- Random sample and independence: each (X, Y) pair comes from a different subject. Several measurements on the same subject, or clustered subjects (families, cages), violate this assumption.
- Pearson: linear relationship and bivariate normality. The test and the confidence interval assume that (X, Y) follow a two-dimensional normal distribution. Check: draw the scatter plot (XY graph, or pairwise graph of the variables); look for curvature, subgroups or isolated points. The normality tests (Analysis › Describe and Explore › Normality Tests) applied to each variable give a partial indication (normality of each variable does not guarantee joint normality).
- Spearman: monotonic relationship. No distributional assumption for rs itself, but the P value and the confidence interval computed by Variance are approximations (see Calculations).
- No influential outliers for Pearson: a single distant point can create or hide a correlation. Compare Pearson and Spearman: a large gap often signals an influential point or a nonlinear relationship.
- Representative range: restricting the range of a variable (for example studying only adults of average height) decreases r; combining two very different groups can create an artificial correlation.
Step by step in Variance#
- Enter the data in one of the three accepted table types:
- an XY table: Variance computes, for each data set, the correlation between the X column and the Y column. If the data set has replicates, their mean is used (one pair per row);
- a One factor table: each column is a variable, and the values in the same row belong to the same subject; Variance computes the matrix of all pairs of selected columns;
- a Multivariable table: each selected numeric variable enters the matrix; categorical (text) variables are ignored.
- Choose Analysis › Describe and Explore › Correlation (or the Analyze button of the ribbon, then "Correlation" in the "Choose an Analysis" window, where you check the data sets or variables to analyze).
- The "Correlation – settings" window opens. Options tab:
- "Correlation coefficient": "Pearson (assume Gaussian distribution)" (default) or "Spearman (nonparametric)";
- "Missing values" (matrices only): "Use all available pairs for each correlation" (default: each coefficient uses all the rows where both variables are present; the n can differ from one pair to another) or "Delete the entire row if any value is missing" (every incomplete row is removed: all the pairs are based on the same subjects);
- "P value": "Two-tailed" (default), "One-tailed (second group greater)" or "One-tailed (second group smaller)". These labels are shared with the t tests; for a correlation, "greater" tests the alternative hypothesis of a positive correlation, "smaller" that of a negative correlation. Use a one-tailed P value only if the direction was fixed before seeing the data;
- "Confidence level (%)": level of the confidence interval of r (95 by default);
- "Significance level (alpha)": threshold used for the "Significant correlation" row (0.05 by default);
- "Significant digits" and "P value format": presentation of numbers and P values.
- Data sets tab: check the data sets (or variables) to analyze.
- Click OK. A results sheet is created; for a matrix, Variance also creates a "heat map" graph of the "Correlation matrix" output table. To change the choices later: Format › Analysis Settings… (Ctrl+Shift+A).
Calculations#
For n complete pairs (xi, yi) (a pair with a missing member is discarded; at least 3 pairs are required):
x̄ = Σxi / n ȳ = Σyi / n
Sxx = Σ(xi − x̄)² Syy = Σ(yi − ȳ)² Sxy = Σ(xi − x̄)(yi − ȳ)
r = Sxy / √(Sxx · Syy) (Pearson coefficient)
R squared = r²
Test of ρ = 0. Under the null hypothesis (zero correlation in the population, normal data), the statistic follows a Student t distribution with n − 2 degrees of freedom:
t = r · √( (n − 2) / (1 − r²) ) df = n − 2
two-tailed P = 2 × min( P(T ≥ t), P(T ≤ t) ) (capped at 1)
P "second group greater" = P(T ≥ t) (alternative: ρ > 0)
P "second group smaller" = P(T ≤ t) (alternative: ρ < 0)
If |r| = 1, t is infinite and P is 0.
Confidence interval (Fisher z transformation). The distribution of r is skewed; r is transformed into z, which is approximately normal:
z = atanh(r) = ½ · ln( (1 + r) / (1 − r) )
SE = 1 / √(n − 3)
z_low = z − z* · SE z_high = z + z* · SE z* = normal quantile (1 + C)/2
CI of r = [ tanh(z_low), tanh(z_high) ] (C = confidence level, 1.96 for 95%)
The interval is computed only if n ≥ 4 and |r| < 1; otherwise the cell shows "(Very wide)".
Spearman. The values of each variable are replaced by their ranks (average ranks in case of ties), then Variance applies exactly the formulas above to the ranks: rs is the Pearson coefficient of the ranks, the P value comes from the same approximation by the Student t distribution with n − 2 df (it is not the exact permutation P value, which R's cor.test computes by default for n < 1290 without ties), and the confidence interval from the same Fisher transformation with SE = 1/√(n − 3). Both approximations are reasonable for n of about 10 or more; for very small samples, interpret the P value and the interval with caution. The "R squared" row then equals rs², which is not a share of the variance of the raw data.
Matrices. Each cell is computed independently for the pair of variables concerned, with the complete rows of that pair (default option) or the rows complete for all the variables ("Delete the entire row..." option). No correction for multiple testing is applied to the P values of the matrix.
Reading the results#
With an XY table, the tab is called "Pearson r" (or "Spearman r") and contains one column per data set:
- r: the coefficient. Its sign gives the direction of the association, its absolute value the strength. It has no unit and does not change if you change the unit of X or Y.
- 95% CI: the values of the population correlation compatible with the data. A wide interval (small n) means that r is poorly known, even if the P value is small.
- R squared: for Pearson, the fraction of the variance of each variable "shared" with the other (r = 0.7 → 49%).
- P value: probability of observing a correlation at least this strong if the population correlation were zero. A small P value says that ρ ≠ 0, not that the association is strong: with n = 1000, r = 0.1 is highly significant but r² = 1%.
- Significance code: the stars of the chosen P value format (standard style: ns if P ≥ 0.05;
*if P < 0.05;**if P < 0.01;***if P < 0.001;****if P < 0.0001). - Significant correlation (alpha=0.05)?: "Yes" if P < alpha.
- Number of XY pairs: number of pairs actually used.
With a One factor or Multivariable table, three tabs give the matrices: "Pearson r" (or "Spearman r") with 1 on the diagonal, "P values" and "95% CI of r" (empty diagonal). The "Correlation matrix" output table (⊞ tab) contains the coefficients; it is plotted as a heat map, which lets you spot blocks of correlated variables at a glance.
For an XY table, the last tab, "Narrative results", states in sentences, for each data set, the coefficient with its confidence interval, the share of variance in common (R², for Pearson), the P value, the chance of a correlation this strong if the two variables were not correlated, and the conclusion.
Worked example#
Data: Start window, table type Multivariable, "an example", example "Clinical study (continuous, categorical and outcome variables)": 40 subjects, with age (Age, years), weight (Weight, kg), height (Height, m), sex (Sex, M/F), a response to treatment (Response, 0/1), a follow-up time (Time) and an event (Event, 0/1).
Matrix. Run Correlation with all the variables (Pearson, default options). Sex, being categorical, is ignored; the matrix covers 6 variables, that is 15 pairs. A few values:
| Pair | r | 95% CI | P |
|---|---|---|---|
| Weight – Height | 0.8597 | 0.7488 to 0.9238 | < 0.0001 |
| Age – Time | −0.7389 | −0.8539 to −0.5552 | < 0.0001 |
| Age – Response | 0.5095 | 0.2354 to 0.7086 | 0.0008 |
| Age – Weight | −0.1101 | −0.4076 to 0.2086 | 0.4990 |
Hand calculation for Weight – Height. With n = 40: x̄ = 64.8525 kg, ȳ = 1.7070 m, Sxx = 1344.0198, Syy = 0.22184, Sxy = 14.8453.
r = 14.8453 / √(1344.0198 × 0.22184) = 14.8453 / 17.2672 = 0.8597
r² = 0.7392
t = 0.8597 × √(38 / (1 − 0.7392)) = 0.8597 × 12.070 = 10.377 df = 38
P = 1.2 × 10⁻¹² → displayed "<0.0001"
z = atanh(0.8597) = 1.2923 SE = 1/√37 = 0.16440
z ± 1.96 × 0.16440 = 0.9701 to 1.6146 → tanh → 95% CI: 0.7488 to 0.9238
These values are those of Variance. With Spearman, rs = 0.8697 (P < 0.0001): the two coefficients agree, a sign of a linear relationship without a marked outlier.
A limiting case. With the XY example "Simple linear regression" (time and two samples), Pearson gives r = 0.9980 (95% CI 0.9913 to 0.9995) for Sample A; Spearman gives rs = 1 exactly, because Y increases at every time step. The confidence interval of rs then cannot be computed (atanh(1) is infinite) and the cell shows "(Very wide)": this is not an imprecision, but the limit of the method. Remember also that here the time is set by the experimenter: linear regression is the appropriate analysis.
Reporting the results#
"Weight and height were strongly correlated (Pearson coefficient r = 0.86; 95% CI 0.75 to 0.92; n = 40; P < 0.0001, two-tailed test)."
For a matrix: "Pearson correlations among the six continuous variables were computed on the available pairs; P values were not corrected for the 15 comparisons and are presented as exploratory."
Common pitfalls#
- Correlation is not causation: age and follow-up time are correlated (r = −0.74), but one does not "cause" the other in the biological sense; a common factor or the study design can produce the association.
- Do not look only at r: very different scatter plots (a curve, two subgroups, an isolated point) can give the same r. Always plot the data.
- r is not a slope: r = 0.9 does not say by how much Y increases when X increases; that is the role of regression.
- Correlation ≠ agreement: two methods can be correlated at r = 0.99 and differ systematically by 20%.
- X chosen by the experimenter: r then depends on the chosen range; use regression.
- Non-independent data: several points per subject artificially inflate n and make the P value too small.
- Multiplicity: a matrix of 10 variables contains 45 tests; a few P < 0.05 are expected by chance. The P values of the matrix are not corrected; if needed, use Analysis › Describe and Explore › Multiple P Values (FDR) on the P values that interest you.
- Different pairs in different cells: with the default missing-values option, each coefficient can be based on a different subset of subjects.
- Spearman with many ties (scores with a few levels): the P value approximated by the Student t distribution becomes less reliable.
Simple Linear Regression#
Simple linear regression fits a line Y = a + b·X to XY data by the method of least squares: it selects the slope b and the intercept a that minimize the sum of squared vertical deviations between the points and the line. Variance gives the slope and the Y-intercept with their standard error and confidence interval, the X-intercept, R², the standard deviation of the residuals Sy.x and the test "is the slope different from zero?". Options: the runs test, which detects a departure from linearity, the comparison of the slopes and intercepts of several data sets, confidence or prediction bands, the table of residuals, the interpolation of unknowns on a standard curve, and forcing the line through a point.
When to use it#
- You want to describe how Y varies with X, estimate a slope (rate of a reaction, growth rate, sensitivity of an assay) or predict Y from X.
- X is set by the experimenter or measured with little error relative to the range of X values (time, doses, concentrations of standards): it is Y that carries the variability. If X and Y are both subject to comparable errors (two measurement methods), use Deming regression.
- The relationship is linear over the range studied. A curve (saturation, exponential decay, sigmoid) calls for nonlinear regression (chapter "Curve fitting"); avoid linearizations (Scatchard, Lineweaver-Burk), which distort the distribution of the errors.
- You want to compare the slopes, or the intercepts, of several groups: put each group in a data set of the same XY table.
- A standard curve is used to assay unknown samples: interpolation option.
- Several predictors: multiple linear regression. Binary Y (0/1): logistic regression.
Assumptions and checks#
- Linearity: the mean of Y is a linear function of X. Check: the graph of the data with the line; the table of residuals plotted against X (the residuals should scatter randomly around 0, without curvature); the runs test.
- Independence: each point provides independent information. Repeated measurements over time on the same subject, or technical replicates of the same sample, are not independent (see the "Replicates" option).
- Normal distribution of the residuals: the deviations from the line follow a normal distribution; the confidence intervals and the P value depend on it. Check: copy the column of residuals into a One factor table and run Analysis › Describe and Explore › Normality Tests. With many points, moderate departures from normality are of no consequence.
- Constant variance: the scatter of the points around the line is the same over the whole range of X. A funnel-shaped residual plot (scatter increasing with X or with Y) signals nonconstant variance. This analysis is not weighted: in that case use Nonlinear Regression with the "Straight line" equation and a "Weighting" option (for example "Weights 1/Y²"), or transform Y.
- X known without substantial error: a measurement error on X biases the slope toward 0 (attenuation, or regression dilution).
- No influential outlier: an isolated point at one end of the range of X can determine the slope on its own. Examine the graph and the residuals, and check the data before any exclusion.
Step by step in Variance#
- Create an XY table: the X values in the X column, each group in a data set. Y replicates (subcolumns) are accepted, as well as summarized data formats (mean with SD, SEM, %CV or limits): only the means are then used, without weighting. To follow the example: Start window, XY type, "an example", example "Simple linear regression".
- Choose Analysis › Curves and Regression › Simple Linear Regression, the linear regression button in the Analyses group of the ribbon (tooltip "Simple linear regression"), or Analyze then "Simple Linear Regression" in the "Choose an Analysis" window.
- The "Simple Linear Regression – settings" window opens on the Options tab:
- "Interpolate the unknowns on the standard curve" (unchecked): for each row that has a Y value but no X, computes the corresponding X on the line and its confidence interval;
- "Compare the slopes and the intercepts" (checked): compares the lines of the analyzed data sets; at least two data sets are required, with at least 3 points each, and no constraint;
- "Constrain": "No constraint" (default) or "Line must go through the point (X0, Y0)", with the "X0" and "Y0" fields (0 and 0 by default, i.e. a line through the origin);
- "Replicates": "Each replicate as a separate point" (default) or "The mean of the replicates only";
- "Runs test for nonlinearity" (unchecked);
- "Graph": "No bands" (default), "Confidence bands" or "Prediction bands";
- "Table of residuals" (unchecked);
- "Confidence level (%)" (95 by default), "Significant digits" and "P value format";
- "Significance level (alpha)" (0.05 by default): threshold of the "Slope different from zero" row and of the decision to compare the intercepts.
- Data sets tab: check the data sets to fit (one line per data set).
- Click OK. The results sheet is created, and the line (with its bands if you requested them) is added to every graph of the table; a graph is created if none exists. The line is drawn from the smallest to the largest X value of the data set.
At least 3 points per data set are required (2 with a constraint); a data set that does not have enough is not analyzed and does not appear in the results (if no data set has enough, a message says so).
Calculations#
Notation: n points (xi, yi), each replicate counting as one point with the default option; C the confidence level (0.95 by default).
x̄ = Σxi / n ȳ = Σyi / n
Sxx = Σ(xi − x̄)² Syy = Σ(yi − ȳ)² Sxy = Σ(xi − x̄)(yi − ȳ)
Slope b = Sxy / Sxx
Y-intercept a = ȳ − b·x̄
X-intercept −a / b 1/slope = 1 / b
SSres = Σ(yi − a − b·xi)² df = n − 2
Sy.x = √( SSres / (n − 2) ) standard deviation of the residuals
SE(b) = Sy.x / √Sxx
SE(a) = Sy.x · √( 1/n + x̄²/Sxx )
CI : b ± t*·SE(b) and a ± t*·SE(a)
t* = quantile (1 + C)/2 of the Student t distribution with n − 2 df
R² = 1 − SSres / Syy
F = (Syy − SSres) / Sy.x² DFn = 1, DFd = n − 2
P = Prob( F(1, n − 2) ≥ F )
The F test is equivalent to the t test of the slope: F = t² with t = b / SE(b), and the P value is two-tailed (slope different from 0 in either direction). Without a constraint, R² is the square of the Pearson correlation coefficient between X and Y.
Bands. The line predicts Ŷ(x) = a + b·x. Variance computes the bands at 101 points spread between the smallest and the largest X of the data set:
confidence band Ŷ(x) ± t*·Sy.x·√( 1/n + (x − x̄)²/Sxx )
prediction band Ŷ(x) ± t*·Sy.x·√( 1 + 1/n + (x − x̄)²/Sxx )
The confidence band is made of the pointwise confidence intervals of the mean of Y at each x (it is not a simultaneous band of the Working-Hotelling type); it is narrowest at x = x̄ and flares out at the ends. The prediction band should contain, at each x, a new observation with probability C: it adds the scatter of the points (the term 1 under the root) and is therefore much wider.
Interpolation. For an unknown (a row without X; if there are replicates, their mean), X = (Y − a) / b. The confidence interval of X is obtained by intersecting the horizontal line at ordinate Y with the two branches of the confidence band (numerical solution); if the horizontal line does not cross a branch, the cell is left empty. This interval accounts only for the uncertainty of the line, not for the measurement error of the unknown itself.
Line through a point (X0, Y0). Only one parameter is then estimated:
S0xx = Σ(xi − X0)² S0xy = Σ(xi − X0)(yi − Y0)
b = S0xy / S0xx a = Y0 − b·X0
df = n − 1 Sy.x = √( SSres / (n − 1) )
SE(b) = Sy.x / √S0xx SE(a) = |X0| · SE(b) (0 for a line through the origin)
F = ( b / SE(b) )² DFn = 1, DFd = n − 1
R² = 1 − SSres / Syy (can be negative)
bands: Ŷ(x) ± t*·Sy.x·√( (x − X0)²/S0xx ) and Ŷ(x) ± t*·Sy.x·√( 1 + (x − X0)²/S0xx )
R² always compares the line with a horizontal line through ȳ; a constrained line can be worse than that horizontal line, hence a negative R². The comparison of lines is not done when a constraint is applied.
Runs test. The residuals are arranged by increasing X; zero residuals are ignored. With n1 positive residuals, n2 negative residuals and R runs (sequences of residuals with the same sign), Variance computes the exact probability of observing R runs or fewer if the signs were arranged at random:
N = n1 + n2 C(m, j) = number of combinations of j among m
P(R = 2k) = 2 · C(n1 − 1, k − 1) · C(n2 − 1, k − 1) / C(N, n1)
P(R = 2k + 1) = [ C(n1 − 1, k) · C(n2 − 1, k − 1) + C(n1 − 1, k − 1) · C(n2 − 1, k) ] / C(N, n1)
P value (runs) = sum of P(R = r) for r = 2 … R (one-tailed)
Too few runs (small P value) means that the points stay on the same side of the line over ranges of X: the relationship is curved. The test requires at least one residual of each sign.
Comparison of lines (analysis of covariance). For k data sets totaling N points, Variance compares three nested models (Sxx,j, Syy,j and Sxy,j are the sums of data set j, computed around its own means):
separate lines SSsep = Σj SSres,j df = N − 2k
parallel lines common slope bc = Σj Sxy,j / Σj Sxx,j
SScom = Σj Syy,j − (Σj Sxy,j)² / Σj Sxx,j df = N − k − 1
single line SSuni = SSres of a line fitted to all the points df = N − 2
Equal slopes? F = [ (SScom − SSsep) / (k − 1) ] / [ SSsep / (N − 2k) ]
DFn = k − 1, DFd = N − 2k
Equal intercepts? F = [ (SSuni − SScom) / (k − 1) ] / [ SScom / (N − k − 1) ]
DFn = k − 1, DFd = N − k − 1
The second test is computed unless the first is significant (P < α): comparing the intercepts of nonparallel lines is meaningless, since their gap depends on X. Sums of squares no larger than the rounding noise, (64ε)²·Σ(y − y₁)², are treated as zero, as in ANOVA: with lines that fit their points exactly, F is infinite, or undefined (empty cell) when the tested difference is zero too; an undefined test of the slopes (identical slopes) does not prevent the comparison of the intercepts. It then tests whether the parallel lines coincide (same "elevation"). With three or more data sets, these tests are global: they do not say which lines differ.
Reading the results#
"Main results" tab, one column per data set:
- "Fitted parameters": "Slope" (in units of Y per unit of X), "Y-intercept" (predicted Y for X = 0, sometimes outside the range studied and without biological meaning), "X-intercept" (value of X where the line crosses Y = 0) and "1/slope".
- "Std. Error": standard errors of the slope and the Y-intercept.
- "95% CI" (the label follows the chosen level): confidence intervals of the slope and the Y-intercept. If the CI of the slope does not contain 0, the slope is significantly nonzero at the corresponding level.
- "Goodness of Fit": "R squared", the fraction of the variance of Y explained by the line (between 0 and 1 without a constraint), and "Sy.x", the standard deviation of the residuals, in the unit of Y.
- "Slope different from zero": "F", "DFn", "DFd", "P value" and "Slope different from zero" ("Significant" if P < α, otherwise "Not significant"). The P value is the probability of obtaining a slope at least this far from 0 if the true slope were zero.
- "Runs test" (if requested): "P value (runs)". A small P value signals a departure from linearity; a large P value does not prove linearity (the test has low power with few points).
- "Data": "Number of X values" (number of distinct X values), "Count of values" (number of points used, replicates included with the default option) and "Equation" (for example
Y = 1.746*X + 5.615, with "-" instead of "+" if the Y-intercept is negative; four significant digits).
"Comparison of the lines" tab ("Value" column, at least two data sets): under "Equality of the slopes", "F", "DFn", "DFd" and "P value". If the slopes do not differ significantly, "Pooled slope" (the common slope bc) follows, then, under "Equality of the intercepts", "F", "DFn", "DFd" and "P value"; otherwise, a "Conclusion" row states "The slopes are significantly different; intercepts are not compared".
"Interpolated X values" tab (interpolation option): columns "Y", "X" and "95% CI", one section per data set and one row per unknown (row label, or "Row n").
"Residuals" output table ("Table of residuals" option): an XY table whose X column repeats the X values of the points and in which each data set, named after the analyzed data set ("Sample A residuals", for example), contains the residuals yi − Ŷ(xi); the data sets are stacked one below the other. Plot it (Plot These Results) to get the residual plot.
The last tab, "Narrative results", states in sentences, for each data set, the slope with its confidence interval, the share of the variation of Y explained by the line (R²) and the test of a zero slope, then the comparison of the slopes and, when they do not differ, that of the intercepts (with the pooled slope).
Worked example#
Sample data "Simple linear regression" (XY table, time in minutes):
Time (min) 0 2 4 6 8 10 12 14 16 18
Sample A 5.96 8.419 13.49 15.82 19.49 23.37 26.21 29.56 32.75 38.24
Sample B 12.26 13.29 17.41 18.69 18.88 23.44 26.6 27.09 31.55 33.26
Hand calculation for Sample A (n = 10):
x̄ = 9 ȳ = 21.3309
Sxx = 330 Syy = 1010.2155 Sxy = 576.2370
b = 576.2370 / 330 = 1.746173
a = 21.3309 − 1.746173 × 9 = 5.615345
SSres = 4.006179 Sy.x = √(4.006179 / 8) = 0.707653
SE(b) = 0.707653 / √330 = 0.038955
SE(a) = 0.707653 × √(1/10 + 81/330) = 0.415926
t*(0.975, 8) = 2.3060
95% CI of b = 1.746173 ± 2.3060 × 0.038955 = [1.6563, 1.8360]
95% CI of a = 5.615345 ± 2.3060 × 0.415926 = [4.656, 6.574]
R² = 1 − 4.006179 / 1010.2155 = 0.99603
F = (1010.2155 − 4.0062) / 0.500772 = 2009.3 DFn = 1, DFd = 8 P = 6.8 × 10⁻¹¹
Variance displays (default settings):
Sample A Sample B
Fitted parameters
Slope 1.746 1.192
Y-intercept 5.615 11.51
X-intercept -3.216 -9.656
1/slope 0.5727 0.8386
Std. Error
Slope 0.03896 0.06083
Y-intercept 0.4159 0.6495
95% CI
Slope 1.656 to 1.836 1.052 to 1.333
Y-intercept 4.656 to 6.574 10.02 to 13.01
Goodness of Fit
R squared 0.996 0.9796
Sy.x 0.7077 1.105
Slope different from zero
F 2009 384.3
DFn 1 1
DFd 8 8
P value <0.0001 <0.0001
Slope different from zero Significant Significant
Data
Number of X values 10 10
Count of values 10 10
Equation Y = 1.746*X + 5.615 Y = 1.192*X + 11.51
Comparison of slopes. "Comparison of the lines" tab: SSsep = 4.0062 + 9.7692 = 13.7754 (df 16); common slope bc = (576.237 + 393.510) / (330 + 330) = 1.4693 and SScom = 64.3650 (df 17); F = (64.3650 − 13.7754) / (13.7754 / 16) = 58.76, DFn = 1, DFd = 16, P = 9.6 × 10⁻⁷. The slopes differ: Variance does not display the common slope and concludes "The slopes are significantly different; intercepts are not compared". With two data sets, this F is the square of the t of the difference between slopes: (1.7462 − 1.1925) / √(0.86096 × (1/330 + 1/330)) = 7.666, and 7.666² = 58.76.
Runs test. With "Runs test for nonlinearity", the residuals of Sample A arranged by X are 0.345; −0.689; 0.890; −0.272; −0.095; 0.293; −0.359; −0.502; −0.804; 1.194: n1 = 4 positive, n2 = 6 negative and R = 7 runs. Of the C(10, 4) = 210 possible arrangements of the signs, 185 have 7 runs or fewer: "P value (runs)" = 185/210 = 0.8810. Nothing indicates a departure from linearity. For Sample B (7 positive residuals, 3 negative, 7 runs, the maximum possible), P = 1.
Bands. At X = 9 (= x̄), Ŷ = 21.331; the 95% confidence band runs from 20.815 to 21.847 (half-width 2.3060 × 0.7077 × √0.1 = 0.516) and the prediction band from 19.619 to 23.042 (half-width 2.3060 × 0.7077 × √1.1 = 1.712). At X = 0, the confidence band coincides with the CI of the Y-intercept (4.656 to 6.574).
Interpolation. Add an eleventh row with Y = 20 in Sample A and no X, then check "Interpolate the unknowns on the standard curve": the "Interpolated X values" tab gives, at row "Row 11", X = (20 − 5.6153) / 1.7462 = 8.238 and a 95% CI of 7.937 to 8.534.
Line forced through the origin. With "Line must go through the point (X0, Y0)" and X0 = Y0 = 0, Sample B gives a slope of 2.102 (95% CI 1.658 to 2.545, DFd = 9), Sy.x = 6.613 instead of 1.105 and R² = 0.1783 instead of 0.9796: the constrained line describes poorly data whose Y-intercept is clearly positive (11.51; 95% CI 10.02 to 13.01).
Reporting the results#
"The signal increased linearly with time (linear regression, 10 points per sample): slope 1.75 units/min (95% CI 1.66 to 1.84) for sample A and 1.19 units/min (95% CI 1.05 to 1.33) for sample B (R² = 0.996 and 0.980); the slopes differed significantly (F(1, 16) = 58.8; P < 0.0001)."
State the unit of the slope, the number of points (and whether replicates were treated as independent points) and the confidence interval, not only the P value.
Common pitfalls#
- Extrapolating beyond the X values studied: nothing guarantees that the relationship remains linear, and the bands widen rapidly.
- Judging linearity from R²: a smooth curve can give R² = 0.99. Look at the residuals and the runs test.
- Confusing a significant slope with a strong relationship: with many points, a minuscule slope is significant; conversely, P > 0.05 does not prove the absence of a relationship (look at the CI of the slope).
- Swapping X and Y: the regression of Y on X is not the regression of X on Y (the slope of X as a function of Y is not 1/b, unless r = ±1). Put the controlled variable, or the one used for prediction, in X; to compare two measurement methods, use Deming regression.
- Forcing the line through the origin because "Y must be 0 when X = 0": the relationship may not be linear near 0, or the method may have a blank. Constrain only if theory requires it and the data confirm it (the CI of the Y-intercept contains 0); the R² of a constrained line can be negative.
- Non-independent replicates treated as points: with "Each replicate as a separate point", technical replicates of the same sample inflate n and make the CIs too narrow; choose "The mean of the replicates only" instead. The means all have the same weight, whatever their number of replicates.
- Measurement error on X: it biases the slope toward 0. Ordinary regression remains valid for predicting Y from an X measured in the same way, but not for estimating the true slope.
- CI of an interpolated value: it does not include the measurement error of the unknown and therefore underestimates the uncertainty of a single assay.
- Intercepts of nonparallel lines: Variance does not compare them. If the gap between groups at a given value of X interests you, use a multiple linear regression with a categorical group variable, X recentered on that value and the "Include two-way interactions" option.
Deming Regression#
Deming regression fits a line when X and Y are both measured with error, typically to compare two measurement methods applied to the same samples. Ordinary regression assumes X is exact: if X is subject to error, its slope is biased toward 0. Deming regression accounts for both errors, provided the ratio of their variances is known; when the two errors have the same standard deviation, it coincides with orthogonal regression, which minimizes the perpendicular distances from the points to the line. Variance gives the slope, the Y-intercept and the X-intercept, the standard errors of the slope and the Y-intercept estimated by jackknife, and their confidence intervals.
When to use it#
- Comparing two methods (two instruments, two laboratories) that measure the same quantity on the same samples: a slope different from 1 signals a proportional bias, a Y-intercept different from 0 a constant bias.
- More generally, describing the relationship between two variables measured with errors of the same order (so-called "Model II" regression).
- Not for predicting Y from X: for prediction, ordinary regression of Y on X remains the right method, even if X is imprecise, provided that future X values are measured in the same way.
- As a complement to Bland-Altman analysis (chapter "Method comparison and ROC curves"), which describes the agreement between the methods. Correlation, for its part, does not measure agreement.
Assumptions and checks#
- Linear relationship between the true values measured by the two methods. Check: the XY graph with the line.
- Measurement errors that are independent, normally distributed, with zero mean and constant standard deviation over the whole range (constant absolute error). If the error is proportional to the value (constant CV) and the range is wide, unweighted Deming regression is poorly suited; Variance offers neither weighted Deming regression nor the Passing-Bablok method.
- Known ratio of the error variances: equal to 1 (same error standard deviation for both methods, default option), or estimated from repeated measurements. With duplicates, the error standard deviation of a method is estimated by √(Σdi² / 2m), where di is the difference between the two measurements of the i-th sample and m the number of samples measured in duplicate.
- Independent samples covering the whole useful range: a range that is narrow relative to the measurement errors gives a very imprecise slope.
Step by step in Variance#
- Create an XY table: the reference method (or the first method) in X, the other method in Y, one row per sample. Each data set is a separate comparison. If Y has replicates, each counts as a point associated with the same X; to use means, enter them directly.
- Choose Analysis › Curves and Regression › Deming Regression.
- Options tab:
- "Errors": "X and Y have the same SD of errors" (default) or "Enter SD of X and Y errors";
- "SD of X errors" and "SD of Y errors" (1 by default), used only with the second option, each in the unit of its variable; only their ratio matters (two equal values are equivalent to the first option);
- "Confidence level (%)", "Significant digits" and "P value format".
- Data sets tab, then OK. The Deming line is drawn on the graph of the table, from the smallest to the largest X value. At least 3 pairs per data set are required.
Calculations#
λ = ( SD of Y errors / SD of X errors )² (λ = 1 with "X and Y have the same SD of errors")
sxx = Σ(xi − x̄)² / (n − 1) syy = Σ(yi − ȳ)² / (n − 1) sxy = Σ(xi − x̄)(yi − ȳ) / (n − 1)
d = syy − λ·sxx
Slope b = [ d + √( d² + 4·λ·sxy² ) ] / (2·sxy)
Y-intercept a = ȳ − b·x̄
X-intercept −a / b
This is the maximum likelihood estimate of the slope in the model with errors on both variables, when the ratio λ of the error variances (Y over X) is known. The Deming slope always lies between the slope of the ordinary regression of Y on X (sxy/sxx) and the inverse of the slope of the regression of X on Y (syy/sxy); it tends toward the former when λ becomes very large (X almost exact) and toward the latter when λ tends to 0 (Y almost exact).
Jackknife standard errors. Variance repeats the calculation n times, removing one point each time:
b(−i), a(−i) = slope and Y-intercept computed without point i (i = 1 … n)
b̄(·) = mean of the n values b(−i)
SE(b) = √[ (n − 1)/n · Σ ( b(−i) − b̄(·) )² ] (likewise for SE(a))
CI : b ± t*·SE(b) and a ± t*·SE(a), t* = quantile (1 + C)/2 of the t distribution with n − 2 df
The estimates displayed are those of the full sample (not the jackknife bias-corrected version). The analysis computes neither a P value nor R²: to judge a bias, check whether the CI of the slope contains 1 and whether that of the Y-intercept contains 0.
Reading the results#
"Main results" tab, one column per data set:
- "Fitted parameters": "Slope", "Y-intercept" and "X-intercept".
- "Std. Error (jackknife)": "Slope" and "Y-intercept".
- "95% CI": "Slope" and "Y-intercept". A CI of the slope that excludes 1 indicates a significant proportional bias; a CI of the Y-intercept that excludes 0, a significant constant bias.
- "Number of XY pairs".
Worked example#
Blood glucose (mmol/L) of 12 samples measured by two methods, entered in an XY table:
Method A (X) 4.5 4.4 5.3 5.2 6.4 6.1 6.1 7.4 7.3 8.2 7.9 9.0
Method B (Y) 4.41 5.54 5.16 6.38 6.30 7.32 6.83 7.65 8.37 8.00 9.12 9.14
Hand calculation with the default options (λ = 1):
x̄ = 6.48333 ȳ = 7.01833
sxx = 2.219697 syy = 2.327306 sxy = 2.088424
d = 2.327306 − 2.219697 = 0.107609
b = [ 0.107609 + √(0.107609² + 4 × 2.088424²) ] / (2 × 2.088424)
= (0.107609 + 4.178234) / 4.176848 = 1.02610
a = 7.01833 − 1.02610 × 6.48333 = 0.36582
SE(b) jackknife = 0.16023 t*(0.975, 10) = 2.2281
95% CI of b = 1.02610 ± 2.2281 × 0.16023 = [0.6691, 1.3831]
Variance displays:
Fitted parameters
Slope 1.026
Y-intercept 0.3658
X-intercept -0.3565
Std. Error (jackknife)
Slope 0.1602
Y-intercept 1.07
95% CI
Slope 0.6691 to 1.383
Y-intercept -2.018 to 2.75
Number of XY pairs 12
On the same data, simple linear regression gives a slope of 0.9409 (95% CI 0.656 to 1.226) and the inverse of the slope of X on Y is 2.327306 / 2.088424 = 1.1144: the Deming slope (1.026) lies between the two, and the ordinary slope is attenuated by the error on X. With "Enter SD of X and Y errors", "SD of X errors" = 0.2 and "SD of Y errors" = 0.3 (λ = 2.25), the slope becomes 0.9917 (95% CI 0.650 to 1.334) and the Y-intercept 0.5886 (95% CI −1.717 to 2.894).
Interpretation: the CI of the slope contains 1 and that of the Y-intercept contains 0, so no bias is demonstrated. But these intervals are wide: a proportional bias from −33% to +38% remains compatible with the data. Twelve samples are not enough to conclude that the methods are equivalent.
Reporting the results#
"Method B was compared with method A on 12 samples by Deming regression (ratio of error variances assumed equal to 1): slope 1.03 (95% CI 0.67 to 1.38, jackknife standard error), Y-intercept 0.37 mmol/L (95% CI −2.02 to 2.75). No constant or proportional bias was demonstrated, but the study cannot exclude a proportional bias of the order of ±35%."
Always state the ratio of error variances used and, if possible, complete the analysis with a Bland-Altman plot.
Common pitfalls#
- Ordinary regression to compare methods: its slope is biased toward 0 as soon as X is imprecise; the discrepancy is larger the narrower the range is relative to the errors.
- Wrong ratio of error variances: assuming equal standard deviations when one method is much more precise than the other biases the slope. If the ratio is poorly known, repeat the analysis with several plausible values and check that the conclusion does not change.
- High correlation ≠ agreement: r = 0.99 excludes neither a constant bias nor a proportional bias.
- CI containing 1 ≠ equivalence: it only means that no bias was detected; judge the width of the CI against the clinically acceptable bias.
- Swapping X and Y: with "X and Y have the same SD of errors", the slope obtained becomes exactly 1/b (the line is the same); with entered standard deviations, swap them too.
- Outliers: an outlying sample strongly influences the slope and its jackknife standard error; examine the graph and the Bland-Altman plot.
- Proportional error over a wide range: unweighted regression gives too much weight to the high values.
- Using the Deming line to predict Y from X: use ordinary regression.
Multiple Linear Regression#
Multiple linear regression explains a continuous variable Y by several explanatory variables, continuous or categorical: Y = β0 + β1·X1 + … + βk·Xk + ε. The coefficients are estimated by least squares; each measures the effect of its variable when the other variables in the model are held constant ("adjusted" effect). Variance gives the coefficients with their standard error, confidence interval, t test and variance inflation factor (VIF), then R², adjusted R², Sy.x, AICc and the overall F test. One option adds the interactions between pairs of variables; another replaces least squares with Poisson regression, suited to counts.
When to use it#
- Several factors influence Y and you want the effect of each adjusted for the others (accounting for measured confounders), or a prediction equation.
- You mix continuous and categorical variables, for example to compare groups while adjusting for a covariate (analysis of covariance).
- You want to know whether the effect of one variable depends on another (interaction).
- Y is a count (number of cells, colonies, events): "Poisson (Y is a count)" option.
- Binary Y: multiple logistic regression; survival time with censoring: Cox model; a single continuous X: simple linear regression (same results).
Assumptions and checks#
- Linearity and additivity: the mean of Y varies linearly with each continuous variable, the others being fixed, and the effects add up (except for interactions included in the model).
- Independence of the observations: one row of the table corresponds to one independent subject.
- Normally distributed residuals with constant variance (least squares). Check: the graph created automatically from the "Actual vs predicted" table shows the observed values and the residuals as a function of the predicted values; the residuals should form a horizontal band without curvature or funnel shape.
- Limited collinearity among the explanatory variables: look at the "VIF" column.
- Sufficient sample size: at least 10 to 20 observations per estimated coefficient is often recommended.
- Explanatory variables measured without substantial error.
- Poisson regression: independent counts, logarithm of the mean linear in the explanatory variables, variance equal to the mean (no overdispersion).
Step by step in Variance#
- Create a Multivariable table: one row per subject, one column per variable. A variable containing text (M/F) is categorical; a variable coded with numbers is treated as continuous, unless you give it the Categorical type (right-click on the column header: Auto, Continuous, Categorical, Label). The reference level of a categorical variable is its first level, that is, in practice the first one encountered when reading the table from top to bottom. To follow the example: Multivariable type, sample data "Clinical study (continuous, categorical and outcome variables)".
- Choose Analysis › Curves and Regression › Multiple Linear Regression.
- Model tab:
- "Dependent variable (Y)": the variable to explain (list);
- "Independent variables": the explanatory variables (check boxes). If none is checked, Variance takes all the other variables checked in the "Data sets" tab, except those of Label type;
- "Include two-way interactions" (unchecked): adds the product of each pair of variables;
- "Include an intercept" (checked): constant term β0;
- "Regression type": "Least squares" (default) or "Poisson (Y is a count)";
- "Model terms" (empty by default): the terms of the model, one per line or separated by commas: a variable (
Age), an interaction (Age*Sex,Age*Sex*Dose) or a power (Age^2,Age^3); names are written as in the table, case ignored, a space may be written_. Empty: the variables checked above (and their two-way interactions if the box is checked); with terms, these boxes are ignored.
- Compare tab: "Compare with the same model without" (empty by default): the terms to remove to obtain a simpler model, nested in the first, separated by commas (for example
Age*Sex, Age^2). Both models are fitted to the same rows and compared (see Calculations). - Options tab: "Confidence level (%)", "Significant digits" and "P value format".
- Data sets tab, then OK. Only complete rows (no missing value for Y or for the model variables) are used; at least one more than the number of coefficients is required, otherwise Variance displays "not enough complete rows for this model". A graph of the "Actual vs predicted" table is created.
Calculations#
Model matrix. Variance builds a column of 1s (if "Include an intercept" is checked), one column per continuous variable, L − 1 indicator columns per categorical variable with L levels (named "Variable[level]", equal to 1 for the subjects of that level and 0 otherwise; the reference level, the first level present in the rows analysed, has no column, and a level without any subject is ignored) and, with interactions, the product of each pair of columns belonging to two different variables (named "A:B").
y = Xβ + ε X: n × p matrix (p columns, constant included)
X': transpose of X
β̂ = (X'X)⁻¹ X'y (computed by a Householder QR decomposition)
ŷ = Xβ̂ ei = yi − ŷi SSres = Σ ei²
df = n − p s² = SSres / (n − p) Sy.x = s
SE(β̂j) = s · √[ (X'X)⁻¹ ]jj
t = β̂j / SE(β̂j) two-tailed P, t distribution with n − p df
CI: β̂j ± t*·SE(β̂j) t* = quantile (1 + C)/2 of the t distribution with n − p df
SStot = Σ(yi − ȳ)² (Σyi² without a constant)
SSreg = Σ(ŷi − ȳ)² (Σŷi² without a constant); SSreg = SStot − SSres
R² = SSreg / SStot = 1 − SSres / SStot Multiple R = √R²
Adjusted R² = 1 − (1 − R²)·(n − 1)/(n − p) (n instead of n − 1 without a constant)
F = [ SSreg / (p − 1) ] / s² DFn = p − 1, DFd = n − p (DFn = p without a constant)
RMSE = √( SSres / n )
AICc = n·ln(SSres / n) + 2K + 2K(K + 1) / (n − K − 1) K = p + 1
VIFj = 1 / (1 − R²j) R²j: R² of the regression of column j on the other columns kept
and a constant (even when the model has no constant)
A column collinear with the preceding ones (a linear combination of the columns retained before it, from which it departs by less than 10⁻⁹ times its norm) is removed before the fit: its coefficient is left empty and p counts only the retained columns. The VIF is computed for each retained column, including each indicator and each interaction product; it is meaningful only with a constant in the model. It is infinite (empty cell) when the column is, together with the constant, a combination of the other columns within the same tolerance (this happens in a model without a constant), and empty for a column without variability. The F test compares the model with a horizontal line Y = ȳ (with Y = 0 without a constant); when no column is left besides the constant, R² is 0 and F and its P value stay empty.
With a constant, the fit is computed on the columns and on Y each minus a common value (an exact subtraction for nearby values), which does not change the model; the estimates and their covariance are then moved back exactly to the original columns. Variables close to 10⁹ thus keep all their digits. SSreg is computed from the fitted values, which keeps a small R² precise.
Poisson regression. The model is log μi = xi'β, where μi is the expected mean count of subject i, and Yi follows a Poisson distribution with mean μi. The coefficients are estimated by maximum likelihood, using iteratively reweighted least squares (IRLS):
start: β0 = ln ȳ (with a constant), other coefficients zero
iteration: η = Xβ, μ = exp(η), W = diag(μ), z = η + (y − μ)/μ, β ← (X'WX)⁻¹ X'Wz
step: halved (up to 30 times) as long as it would increase −2·LL
stop: when −2·LL changes by less than 10⁻¹⁰ in relative value (100 iterations at most)
SE(β̂j) = √[ (X'WX)⁻¹ ]jj z = β̂j / SE(β̂j) P = 2·[1 − Φ(|z|)]
CI: β̂j ± z*·SE(β̂j) z* = quantile (1 + C)/2 of the normal distribution
Rate ratio = exp(β̂j), CI = exponential of the limits
LL = Σ [ yi·ln μi − μi − ln(yi!) ]
Deviance = 2·Σ [ yi·ln(yi/μi) − (yi − μi) ] (term equal to μi if yi = 0)
χ² = 2·(LL − LL0), df = p − 1 LL0: constant-only model μi = ȳ
without a constant: df = p LL0: all coefficients zero, μi = 1
AICc = −2·LL + 2p + 2p(p + 1) / (n − p − 1)
Without a constant, the reference model of the likelihood ratio test is the one in which all the coefficients are zero (η = 0, i.e. μi = 1), the only one that is nested in a model without a constant; the test then has p degrees of freedom.
Model terms. An interaction is the product of its factors: for two continuous variables, a column A·B; with a categorical variable, one column per indicator column ("Age:Sex[F]"); Age*Sex*Dose gives the products of the three. A power Age^2 adds the column Age² (continuous variables only; Age*Age is the same as Age^2). A term written twice counts once. Respect the hierarchy of terms: a model that contains Age*Sex should usually contain Age and Sex too, and a model that contains Age^2 should contain Age.
Comparison of nested models. With "Compare with the same model without", Variance also fits the model without the terms given, on the same rows, and compares the two:
least squares: F = [(SS_simpler − SS_full) / (df_simpler − df_full)] / (SS_full / df_full)
SS_simpler − SS_full = Σ(ŷ_full − ŷ_simpler)²
P from the F distribution with (df_simpler − df_full, df_full) df
Poisson: χ² = deviance_simpler − deviance_full, with as many df as coefficients removed
probability that the full model is the better one = 1 / (1 + exp[(AICc_full − AICc_simpler) / 2])
The test answers "do the removed terms improve the fit more than chance would explain?"; the AICc, which penalizes the number of parameters, compares the two models without treating one of them as a null hypothesis (the probability is the Akaike weight). Removing every term compares with the model reduced to the constant, which gives back the overall F test.
Reading the results#
Least squares. "Parameter estimates" tab, columns "Estimate", "Std. Error", "95% CI", "|t| or |z|", "P value" and "VIF", one row per coefficient ("Intercept", name of each continuous variable, "Sex[F]" for an indicator, "Age:Height" for an interaction):
- the coefficient of a continuous variable is the change in the mean of Y when that variable increases by one unit, the others remaining constant; that of an indicator is the difference between that level and the reference level, at equal values of the other variables; "Intercept" is the predicted value when all the continuous variables equal 0 (at the reference levels), often outside the observed range;
- "|t| or |z|" is an absolute value: the direction of the effect is given by the sign of the estimate;
- "VIF" is 1 in the absence of collinearity; a VIF above 5 or 10 (usual thresholds) signals strong collinearity, which inflates the standard error of the coefficient (by a factor of √VIF).
Next, in the same tab, "Goodness of fit": "Degrees of freedom" (n − p), "Multiple R", "R squared", "Adjusted R squared", "Sum of squares" (sum of squared residuals), "Sy.x", "RMSE" and "AICc"; then "Is the model better than a horizontal line?": "F", "DFn", "DFd" and "P value" (a small P value indicates that at least one coefficient, constant excluded, is nonzero); finally "Number of observations".
Poisson. Same "Parameter estimates" tab (the "|t| or |z|" column contains |z|, the "VIF" column stays empty), then "Goodness of fit": "Deviance", "Log likelihood", "AICc" and "Likelihood ratio χ² vs intercept only" ("Likelihood ratio χ² vs all coefficients zero" without a constant; statistic in the first column, P value in the "P value" column). A "Warning" row precedes these rows if the fit did not converge within 100 iterations. The "Rate ratios" tab (columns "Rate ratio" and "95% CI", without the constant) gives the multiplicative factor of the expected count when the variable increases by one unit.
"Actual vs predicted" output table. X = "Predicted" (ŷ), data sets "Actual" (y) and "Residual" (y − ŷ); this is what the automatically created graph shows.
- "Comparison of models" tab (Compare tab filled in): "Simpler model" ("without" followed by the terms removed), "Test", then "F", "DFn" and "DFd" (least squares) or "Chi-square" and "df" (Poisson), "P value", "Preferred model (alpha = 0.05)" (the full model if P < 0.05, otherwise the simpler model), "R squared (simpler model)" and "R squared (full model)" (least squares), "AICc (simpler model)", "AICc (full model)" and "Probability the full model is better (%)".
The last tab, "Narrative results", states in sentences the overall test (does the model fit better than a horizontal line?, with R² and adjusted R²), then, for each variable, its coefficient (its rate ratio with Poisson regression) with its confidence interval and its P value, the other variables being held constant, and finally the comparison with the nested model, when it is requested.
Worked example#
Sample data "Clinical study" (40 subjects). "Dependent variable (Y)": Weight; "Independent variables": Age, Height and Sex. The first subject is a man: M is the reference level and the indicator column is called "Sex[F]". Variance displays:
Estimate Std. Error 95% CI |t| or |z| P value VIF
Intercept -23.82 20.12 -64.63 to 16.99 1.184 0.2442
Age 0.0414 0.04446 -0.04877 to 0.1316 0.9312 0.3580 1.046
Height 51.59 11.19 28.89 to 74.3 4.609 <0.0001 3.171
Sex[F] -2.989 1.661 -6.358 to 0.3803 1.799 0.0804 3.148
Goodness of fit
Degrees of freedom 36
Multiple R 0.8748
R squared 0.7652
Adjusted R squared 0.7456
Sum of squares 315.6
Sy.x 2.961
RMSE 2.809
AICc 94.38
Is the model better than a horizontal line?
F 39.11
DFn 3
DFd 36
P value <0.0001
Number of observations 40
Hand check of a few rows (n = 40, p = 4):
Sy.x = √(315.559 / 36) = 2.9607 RMSE = √(315.559 / 40) = 2.8087
Adjusted R² = 1 − (1 − 0.76521) × 39/36 = 0.74565
F = (0.76521 / 3) / ((1 − 0.76521) / 36) = 39.11 DFn = 3, DFd = 36
t (Height) = 51.594 / 11.194 = 4.609 P = 4.9 × 10⁻⁵ (36 df)
95% CI (Height) = 51.594 ± 2.0281 × 11.194 = [28.89, 74.30]
AICc = 40 × ln(315.559 / 40) + 2 × 5 + 2 × 5 × 6 / 34 = 82.619 + 10 + 1.765 = 94.38
Interpretation: at equal age and sex, weight increases by 51.6 kg per meter of height, i.e. 0.52 kg per cm (95% CI 0.29 to 0.74). At equal age and height, women weigh 3.0 kg less than men (95% CI −6.4 to +0.4; P = 0.08): the difference is not significant, but a gap of several kilograms remains compatible with the data. No effect of age is detected (95% CI −0.05 to +0.13 kg per year). The predicted weight of a 50-year-old woman measuring 1.65 m is −23.823 + 0.0414 × 50 + 51.594 × 1.65 − 2.989 = 60.39 kg.
The VIFs of Height and Sex (about 3.2) reflect the correlation between height and sex (r = −0.83 between Height and the indicator Sex[F]). Without Sex in the model, the coefficient of Height becomes 68.08 (standard error 6.62; VIF 1.045): the standard error of Height is 1.7 times larger when Sex is present, and part of the "height" effect of the reduced model was a "sex" effect.
With "Include two-way interactions", the model has 7 coefficients (including "Age:Height", "Age:Sex[F]" and "Height:Sex[F]"): R² = 0.794, adjusted R² = 0.7566, but AICc = 98.03, higher than 94.38 (the model with interactions is not better), and VIFs as high as 2,140, because the products are formed on uncentered variables.
Reporting the results#
"In a multiple linear regression (least squares; n = 40), weight was associated with height at equal age and sex (+0.52 kg per cm; 95% CI 0.29 to 0.74; P < 0.0001), but neither with age (+0.04 kg per year; 95% CI −0.05 to 0.13; P = 0.36) nor significantly with sex (women −3.0 kg; 95% CI −6.4 to 0.4; P = 0.08). The model explained 77% of the variance in weight (adjusted R² 0.75; F(3, 36) = 39.1; P < 0.0001)."
Give the complete list of the variables in the model, the coding of categorical variables (reference level) and the number of observations used.
Common pitfalls#
- Too many variables for the sample size: the model fits the noise (overfitting), R² is inflated and the coefficients are unstable.
- Collinearity: high VIFs make the coefficients imprecise, even of unexpected sign; a coefficient then describes the effect of a variable "at equal values of the others", a situation that is sometimes unrealistic when the variables move together.
- Interactions on uncentered variables: each main effect becomes the effect of the variable when the other equals 0 (here, the effect of age for a height of 0 m) and the VIFs explode. Center the variables first (by subtracting their mean or a reference value).
- Interpreting coefficients as causal effects: the adjustment covers only the variables that were measured and included; do not adjust for an intermediate variable in the causal chain.
- Categories coded with numbers (1, 2, 3): without the Categorical type, they are treated as a continuous variable.
- "Independent variables" left empty: all the other variables enter the model, including outcome variables (Response, Event in the example).
- Missing values: every incomplete row is excluded; check "Number of observations". Two models can be compared (R², AICc) only if they are based on the same rows and the same Y variable.
- R² always increases when a variable is added: compare models with the adjusted R² or the AICc (the smaller is preferable).
- Model without a constant: R² and F are then computed relative to Y = 0, not to ȳ. For Weight as a function of Height alone, R² is 0.9968 without a constant versus 0.739 with one: these values are not comparable. The VIFs, for their part, are always computed with a constant in the auxiliary regressions.
- Stepwise selection of variables based on their P value: Variance does not offer it, and the P values obtained after a selection are too optimistic.
- Poisson and overdispersion: if the deviance is clearly greater than its degrees of freedom n − p, the variance exceeds the mean, the standard errors are underestimated and the P values too small. Variance offers neither a quasi-Poisson model, nor a negative binomial, nor an exposure term (offset): the counts must correspond to equal observation durations or volumes.
Simple Logistic Regression#
Simple logistic regression relates a binary variable Y (1 = yes, 0 = no: death, response to treatment, presence of a disease) to a continuous variable X. It models the probability that Y equals 1 by a sigmoid curve, π(X) = 1 / (1 + e^−(β0 + β1·X)); in other words, the logarithm of the odds (logit) varies linearly with X. The coefficients are estimated by maximum likelihood. Variance gives β0 and β1 with their standard error and confidence interval, the value of X at which the probability is 50%, the odds ratio per unit of X, two pseudo-R², the deviance, the likelihood ratio test, the Wald P value and the area under the ROC curve; the fitted curve is drawn on the graph of the data.
When to use it#
- Y is binary and the predictor is continuous (dose, age, concentration of a marker).
- Quantal response to a dose (each animal responds or not): X = dose or log dose, Y = 0 or 1, one replicate per animal.
- Several predictors, or a categorical predictor: multiple logistic regression. Comparison of two proportions: contingency tables.
- If you have proportions (k responders among n subjects) rather than individual data, enter them as n replicates: k values of 1 and n − k values of 0.
Assumptions and checks#
- Independence of the observations (one subject per value).
- Logit linear in X: the odds are multiplied by the same factor for each unit of X. A U-shaped relationship (high risk at both extremes) is not described by this model. Check: group X into classes and compare the observed proportions of Y = 1 with the fitted curve; multiple logistic regression also provides the Hosmer-Lemeshow test.
- Enough events: at least 10 subjects of the rarest category per estimated coefficient is often recommended.
- No complete separation: if a value of X perfectly separates the 0s from the 1s, the maximum likelihood estimate does not exist (infinite coefficients). Variance flags this with a "Warning" row.
- Y coded exactly 0 or 1.
Step by step in Variance#
- Create an XY table: the predictor in X, the response (0 or 1) in Y. Several subjects with the same X can be entered as replicates (each replicate is a subject) or on separate rows. Each data set is analyzed separately. To follow the example, copy the Age (as X) and Response (as Y) columns of the "Clinical study" sample data into an XY table.
- Choose Analysis › Curves and Regression › Simple Logistic Regression.
- Options tab:
- "Report ROC curve and area under the curve" (checked): adds the area under the ROC curve of the predicted probabilities, with its standard error, its confidence interval and the P value of the test "area = 0.5", and an output table "ROC curve: <data set>" (100% − specificity in X, sensitivity in Y) to draw the curve;
- "Confidence level (%)", "Significant digits" and "P value format".
- Data sets tab, then OK. The fitted logistic curve (probability that Y = 1 as a function of X) is drawn on the graph of the table, from the smallest to the largest X value. If Y contains a value other than 0 or 1, the data set is not fitted: a "Could not fit" row gives the reason (a message is displayed if no data set can be fitted).
Calculations#
π(x) = Prob(Y = 1 | X = x) = 1 / ( 1 + exp(−(β0 + β1·x)) )
logit π = ln[ π / (1 − π) ] = β0 + β1·x
LL(β) = Σ [ yi·ln πi + (1 − yi)·ln(1 − πi) ] log-likelihood
Estimation (IRLS). Variance maximizes LL by iteratively reweighted least squares, equivalent here to the Newton-Raphson method:
start : β0 = ln[ ȳ / (1 − ȳ) ], β1 = 0 (ȳ = proportion of Y = 1)
iteration : ηi = β0 + β1·xi πi = 1 / (1 + e^−ηi) wi = πi·(1 − πi)
zi = ηi + (yi − πi) / wi
β ← (X'WX)⁻¹ X'Wz X: column of 1s and column of xi
step : if a step increases the deviance −2·LL, it is halved (up to 30 times)
stop : when the deviance changes by less than 10⁻¹⁰ in relative value and the coefficients
by less than 10⁻⁸ (100 iterations at most)
The computation uses X centered and scaled (unit root mean square), then the coefficients and their standard errors are moved back exactly to the scale of X: the result does not depend on an extreme offset or scale of the data. A slope at the level of rounding noise (below 10⁻¹⁰ for X centered and scaled) is 0: the predicted probabilities are then all equal and "X where Y = 50%" is not defined.
In case of complete or quasi-complete separation, the maximum likelihood does not exist: the coefficients grow at each iteration and predicted probabilities become numerically equal to 0 or 1. Variance detects this (predicted probability within 10⁻¹⁰ of 0 or 1) and adds a "Warning" row at the top of the results; it does the same when the deviance has not converged within 100 iterations.
Tests, intervals and indices.
SE(β̂j) = √[ (X'WX)⁻¹ ]jj (Fisher information at the final estimates)
Wald: z = β̂1 / SE(β̂1) P = 2·[1 − Φ(|z|)]
CI : β̂j ± z*·SE(β̂j) z* = quantile (1 + C)/2 of the normal distribution (Wald CI)
Odds ratio = exp(β̂1) CI = [ exp(lower limit of β1), exp(upper limit of β1) ]
X where Y = 50%: −β̂0 / β̂1
LL0 = n·[ ȳ·ln ȳ + (1 − ȳ)·ln(1 − ȳ) ] model without X
Chi-square = 2·(LL − LL0) 1 df P = Prob(χ²₁ ≥ Chi-square)
Deviance = −2·LL
Tjur's R² = mean of the π̂i of the subjects with Y = 1 − mean of the π̂i of the subjects with Y = 0
Cox-Snell's R² = 1 − exp[ 2·(LL0 − LL) / n ]
Area = proportion of pairs (one subject with Y = 1, one subject with Y = 0) in which π̂ is larger
for the subject with Y = 1 (ties counted ½)
The odds ratio is the factor by which the odds are multiplied when X increases by one unit; for an increase of Δ units, it equals exp(Δ·β̂1), with the CI exp(Δ·limits). The intervals are Wald intervals, not profile likelihood intervals.
Reading the results#
"Main results" tab, one column per data set:
- "Fitted parameters": "β0 (intercept)" (logit of the probability when X = 0), "β1 (slope)" (change in the logit per unit of X), "X where Y = 50%" (X at which the probability is 0.5, for example an effective dose 50) and "Odds ratio (per unit X)".
- "Std. Error": "β0" and "β1".
- "95% CI": "β0", "β1" and "Odds ratio". A CI of the odds ratio that excludes 1 corresponds to a Wald P value below the threshold.
- "Goodness of fit": "Tjur's R squared", "Cox-Snell's R squared" and "Deviance". The pseudo-R² are not shares of explained variance: Tjur's is the difference between the mean predicted probabilities of the two groups (from 0 to 1); Cox-Snell's cannot reach 1. The deviance can be interpreted only by comparing models fitted to the same data.
- "Likelihood ratio test": "Chi-square" and "P value" (test of β1 = 0 by comparison with the model without X), then "Wald P value (β1)".
- "Area under the ROC curve": "Area" (0.5 = no discrimination, 1 = perfect discrimination), "Std. Error", "95% CI" and "P value" (test of the hypothesis "area = 0.5"), computed as for multiple logistic regression (see below).
- "Data": "Number of observations".
- At the top of the table, if needed: "Warning" (no convergence, or separation) and "Could not fit" (data set that could not be fitted, with the reason).
Worked example#
Age (X, years) and Response (Y) of the 40 subjects of the "Clinical study" sample data, of whom 12 are responders. Variance displays:
Fitted parameters
β0 (intercept) -8.753
β1 (slope) 0.1468
X where Y = 50% 59.63
Odds ratio (per unit X) 1.158
Std. Error
β0 3.014
β1 0.05295
95% CI
β0 -14.66 to -2.846
β1 0.04301 to 0.2506
Odds ratio 1.044 to 1.285
Goodness of fit
Tjur's R squared 0.2853
Cox-Snell's R squared 0.2652
Deviance 36.54
Likelihood ratio test
Chi-square 12.33
P value 0.0004
Wald P value (β1) 0.0056
Area under the ROC curve
Area 0.8318
Std. Error 0.07861
95% CI 0.6778 to 0.9859
P value <0.0001
Data
Number of observations 40
Hand check:
ȳ = 12/40 = 0.3
LL0 = 40 × [0.3 × ln 0.3 + 0.7 × ln 0.7] = −24.4346
LL = −18.2717 at the maximum Deviance = 36.543
Chi-square = 2 × (−18.2717 + 24.4346) = 12.326 P = 0.00045 (1 df)
z (Wald) = 0.14679 / 0.052952 = 2.772 P = 0.0056
Odds ratio = e^0.14679 = 1.1581 95% CI = e^(0.14679 ± 1.96 × 0.052952) = [1.0439, 1.2848]
X where Y = 50%: 8.7526 / 0.14679 = 59.63 years
Cox-Snell = 1 − exp(2 × (−24.4346 + 18.2717) / 40) = 0.2652
Interpretation: each year of age multiplies the odds of response by 1.158 (+16%), i.e. by e^(10 × 0.14679) = 4.34 per decade (95% CI 1.54 to 12.25). The predicted probability of response is 0.196 at 50 years, 0.5 at 59.6 years and 0.821 at 70 years. The likelihood ratio P value (0.0004) and the Wald P value (0.0056) differ appreciably with 40 subjects: the likelihood ratio test is generally preferred. The same model run with Multiple Logistic Regression (Age alone) gives the same coefficients, plus McFadden 0.2522, Nagelkerke 0.376, Hosmer-Lemeshow 11.28 (P = 0.1863) and a classification table (77.5% of subjects correctly classified).
Reporting the results#
"The probability of response increased with age (logistic regression, n = 40, 12 responders): odds ratio 1.16 per year (Wald 95% CI 1.04 to 1.28), i.e. 4.3 per decade (95% CI 1.5 to 12.3); likelihood ratio test χ²(1) = 12.3, P = 0.0004. The estimated probability of response reached 50% at 59.6 years; area under the ROC curve 0.83."
Common pitfalls#
- Odds ratio per unit: its value depends on the unit of X (per year or per decade); express it for a difference that is meaningful.
- Odds ratio ≠ relative risk: when the event is common (here 30%), the odds ratio exaggerates the ratio of the probabilities.
- Wald for small samples: the Wald CI and P value are approximate when n is small or the coefficient is large; prefer the likelihood ratio test.
- Complete or quasi-complete separation: huge coefficients and standard errors, immense CIs; the estimate does not exist and Variance does not display a warning. Describe the data instead (no responder below such a threshold).
- Optimistic area under the ROC curve: it is computed on the data that were used to fit the model.
- Extrapolating the curve beyond the observed X values.
Multiple Logistic Regression#
Multiple logistic regression extends simple logistic regression to several explanatory variables, continuous or categorical: logit π = β0 + β1·X1 + … + βk·Xk, where π is the probability that the binary outcome equals 1. Each odds ratio is adjusted for the other variables in the model. Variance gives the coefficients with their standard error, CI and Wald test, the odds ratios and their CIs, four pseudo-R², the likelihood ratio test of the model, the Hosmer-Lemeshow test, the AICc, the area under the ROC curve, a classification table for a chosen cutoff, as well as the ROC curve and a forest plot of the odds ratios.
When to use it#
- The outcome is binary and you want the effect of several factors, each adjusted for the others (accounting for confounders), or a prediction score.
- Case-control studies: the odds ratio is the natural measure of association there (the constant, however, has no meaning, since the proportion of cases is fixed by the study design).
- You want to test an interaction between two factors ("Include two-way interactions" option).
- A single continuous predictor: simple logistic regression gives the same coefficients. Time to an event, with censoring: Cox model.
Assumptions and checks#
- Independence of the observations (one subject per row).
- Linear logit for each continuous variable, and additive effects on the logit scale (except interactions).
- Enough events: at least 10 events (of the rarest category) per estimated coefficient is often recommended; below that, the coefficients are unstable and often exaggerated.
- Limited collinearity: this analysis does not display a VIF. The VIF depends only on the explanatory variables: run a multiple linear regression with the same "Independent variables" (any continuous Y variable) to obtain it.
- No separation: no combination of the variables should predict the outcome perfectly (Variance flags this with a "Warning" row).
- Calibration (Hosmer-Lemeshow test) and discrimination (area under the ROC curve) inform you about the quality of the model.
Step by step in Variance#
- Create a Multivariable table, one row per subject. The outcome can be a numeric column coded 0/1, or a categorical variable with exactly two levels: the second level (in order of appearance) is then coded 1; for example, if "No" appears before "Yes", "Yes" equals 1. Categorical explanatory variables are coded by indicators, as in multiple linear regression (reference level: the first one encountered). To follow the example: "Clinical study" sample data.
- Choose Analysis › Curves and Regression › Multiple Logistic Regression.
- Model tab:
- "Outcome variable (0/1)": the outcome;
- "Independent variables": the explanatory variables; if none is checked, Variance takes all the other variables checked in the "Data sets" tab, except those of Label type;
- "Include two-way interactions" (unchecked);
- "Model terms" (empty by default): the terms of the model, one per line or separated by commas: a variable (
Age), an interaction (Age*Sex,Age*Sex*Dose) or a power (Age^2,Age^3); names are written as in the table, case ignored, a space may be written_. Empty: the variables checked above (and their two-way interactions if the box is checked); with terms, these boxes are ignored.
- Compare tab: "Compare with the same model without" (empty by default): the terms to remove to obtain a simpler model, nested in the first, separated by commas (for example
Age*Sex, Age^2). Both models are fitted to the same rows and compared (see Calculations). - Options tab: "Classification cutoff" (0.5 by default, between 0 and 1), "Confidence level (%)", "Significant digits" and "P value format".
- Data sets tab, then OK. A constant is always included; only complete rows are used. A graph of the ROC curve is created. Possible error messages: "the outcome must have exactly two values", "logistic regression needs Y coded as 0 or 1", "design matrix is singular (collinear predictors?)".
Calculations#
Estimation. The model is logit πi = xi'β, where xi is the row of the model matrix (constant, continuous variables, indicators, interaction products). Estimation follows exactly the IRLS algorithm of simple logistic regression (same start, same step halving, same stopping criterion, same detection of separation), with p coefficients. Standard errors, Wald tests (z, P = 2·[1 − Φ(|z|)]), Wald CIs and odds ratios (exp(β̂j), CI = exponential of the limits) are computed as in simple logistic regression, for each coefficient.
Overall quality.
LL0 = n·[ ȳ·ln ȳ + (1 − ȳ)·ln(1 − ȳ) ] constant-only model
G² = 2·(LL − LL0) df = p − 1 P = Prob(χ²(p − 1) ≥ G²)
Tjur = mean of π̂i (Y = 1) − mean of π̂i (Y = 0)
McFadden = 1 − LL / LL0
Cox-Snell = 1 − exp[ 2·(LL0 − LL) / n ]
Nagelkerke = Cox-Snell / [ 1 − exp(2·LL0 / n) ] (Cox-Snell rescaled to a maximum of 1)
AICc = −2·LL + 2p + 2p(p + 1) / (n − p − 1)
Hosmer-Lemeshow test. The subjects are sorted by increasing predicted probability, then divided into G = 10 groups of equal size to within one unit (group g contains the subjects of rank ⌊(g − 1)·n/10⌋ + 1 to ⌊g·n/10⌋):
Og = number of Y = 1 in group g Eg = sum of the π̂i of the group ng = size of the group
H = Σg (Og − Eg)² / [ Eg·(1 − Eg/ng) ] df = G − 2 (8 with 10 groups) P = Prob(χ² ≥ H)
The test requires at least 20 subjects (otherwise the row does not appear). When the predicted probabilities have fewer than 10 distinct values (all explanatory variables categorical, for example), each distinct value forms a group, so that tied subjects are never separated; at least 3 distinct values (G ≥ 3) are then required, otherwise the row does not appear. With 10 or more distinct values, subjects with the same predicted probability can fall into two neighboring groups.
ROC curve and area. The thresholds are placed midway between two successive distinct predicted probabilities (plus one threshold below the smallest and one above the largest). For each threshold, the sensitivity is the proportion of subjects with Y = 1 whose π̂ exceeds the threshold, the specificity the proportion of subjects with Y = 0 whose π̂ does not exceed it. The area A is the Mann-Whitney statistic (proportion of concordant pairs, ties counted ½); its standard error is that of Hanley and McNeil:
n1 = number of Y = 1 n0 = number of Y = 0
Q1 = A / (2 − A) Q2 = 2A² / (1 + A)
SE² = [ A(1 − A) + (n1 − 1)(Q1 − A²) + (n0 − 1)(Q2 − A²) ] / (n1·n0)
CI: score-type interval, as for the ROC curve: the areas θ such that
|A − θ| = z · SE(θ), SE(θ) being the formula above evaluated at θ
P: z = (A − 0.5) / SE0 P = 2·[1 − Φ(|z|)]
SE0² = [ (N + 1) − Σ(t³ − t) / (N(N − 1)) ] / (12 · n1 · n0), N = n1 + n0
(variance of the area under the hypothesis A = 0.5: the Mann-Whitney test)
Classification. A subject is classified as "1" if π̂i ≥ "Classification cutoff".
Terms and comparison of models. The terms are written as for multiple linear regression. The comparison with the model without the terms given uses the likelihood ratio test: χ² = deviance_simpler − deviance_full (it is also G²_full − G²_simpler), with as many df as coefficients removed, and the AICc of both models (probability of the better model from the Akaike weights).
Reading the results#
- "Parameter estimates" tab: columns "β", "Std. Error", "95% CI", "|z|" and "P value", one row per coefficient ("Intercept", name of the variables, "Sex[F]" for an indicator, "A:B" for an interaction). Each β is the change in the logit for one unit of the variable, the others remaining constant.
- "Odds ratios" tab: "Odds ratio" and "95% CI". The "Intercept" row gives exp(β0), the odds when all the continuous variables equal 0 at the reference levels, rarely interpretable. An indicator's odds ratio compares that level with the reference level; its inverse (1/OR, with the inverted CI) compares the reference with that level.
- A "Warning" row ends the "Parameter estimates" tab if the fit did not converge or in case of separation: the estimates are then not reliable.
- "Goodness of fit" tab (columns "Value" and "P value"): "Tjur's R squared", "McFadden's R squared", "Cox-Snell's R squared", "Nagelkerke's R squared", "Log likelihood ratio (G squared)" and its P value (does the model do better than the constant alone?), "Hosmer-Lemeshow statistic" and its P value (a small P value signals a lack of calibration; a large P value does not prove adequacy, especially with few subjects), "AICc" (to compare models fitted to the same subjects: the smaller is preferable) and "Area under the ROC curve" with the P value of the test of the hypothesis "area = 0.5".
- "Classification" tab: columns "Predicted 0", "Predicted 1" and "% correct"; rows "Observed 0" (the percentage is the specificity at the chosen cutoff), "Observed 1" (the sensitivity) and "Total" (the percentage of subjects correctly classified).
- Output tables: "ROC curve" (X = "100% - Specificity%", Y = "Sensitivity%"), drawn automatically, and "Forest plot (odds ratios)" (columns "Odds ratio", "Lower limit" and "Upper limit", without the constant), which is drawn with Plot These Results as a forest plot on a logarithmic axis.
- "Comparison of models" tab (Compare tab filled in): "Simpler model" ("without" followed by the terms removed), "Test", then "Chi-square" and "df", "P value", "Preferred model (alpha = 0.05)" (the full model if P < 0.05, otherwise the simpler model), "AICc (simpler model)", "AICc (full model)" and "Probability the full model is better (%)".
The last tab, "Narrative results", states in sentences the likelihood ratio test of the model (does it predict better than the intercept alone?), the area under the ROC curve of the predicted probabilities, then the odds ratio of each variable with its confidence interval and its P value, and the comparison with the nested model, when it is requested.
Worked example#
"Clinical study" sample data: "Outcome variable (0/1)" = Response (12 responders out of 40), "Independent variables" = Age and Sex (reference: M). Variance displays:
Parameter estimates
β Std. Error 95% CI |z| P value
Intercept -16.95 6.448 -29.59 to -4.309 2.628 0.0086
Age 0.3391 0.1289 0.0864 to 0.5917 2.63 0.0085
Sex[F] -4.968 1.914 -8.719 to -1.216 2.596 0.0094
Odds ratios
Odds ratio 95% CI
Intercept 4.362e-8 1.416e-13 to 0.01344
Age 1.404 1.09 to 1.807
Sex[F] 0.006959 0.0001634 to 0.2963
Goodness of fit Value P value
Tjur's R squared 0.5972
McFadden's R squared 0.5486
Cox-Snell's R squared 0.4884
Nagelkerke's R squared 0.6925
Log likelihood ratio (G squared) 26.81 <0.0001
Hosmer-Lemeshow statistic 6.043 0.6425
AICc 28.73
Area under the ROC curve 0.9345 <0.0001
Classification Predicted 0 Predicted 1 % correct
Observed 0 27 1 96.43
Observed 1 2 10 83.33
Total 29 11 92.5
Hand check (LL = −11.0294 at the maximum, LL0 = −24.4346, n = 40, p = 3):
G² = 2 × (−11.0294 + 24.4346) = 26.810 2 df P = 1.5 × 10⁻⁶
McFadden = 1 − (−11.0294) / (−24.4346) = 0.5486
Cox-Snell = 1 − exp(2 × (−24.4346 + 11.0294) / 40) = 1 − exp(−0.67026) = 0.4884
Nagelkerke = 0.4884 / (1 − exp(2 × (−24.4346) / 40)) = 0.4884 / 0.7053 = 0.6925
AICc = 22.0588 + 2 × 3 + 2 × 3 × 4 / 36 = 28.725
OR (Age) = e^0.33907 = 1.404 95% CI = e^(0.33907 ± 1.96 × 0.12891) = [1.090, 1.807]
Area = 0.9345 SE (Hanley-McNeil) = 0.0518 95% CI (score) = 0.759 to 0.985
SE0 = √(41 / (12 × 12 × 28)) = 0.1008 z = (0.9345 − 0.5) / 0.1008 = 4.31 P < 0.0001
Classification: (27 + 10) / 40 = 92.5% of subjects correctly classified at cutoff 0.5
Interpretation: at equal sex, each year of age multiplies the odds of response by 1.40 (95% CI 1.09 to 1.81). At equal age, the odds for women are 0.7% of those for men (OR 0.0070); put differently, the odds for men are 144 times higher (1/0.006959 = 143.7; 95% CI 3.4 to 6,118). The enormity of this interval reflects the fragility of the estimate: 12 events for 2 variables, i.e. 6 events per coefficient. Sex may also reflect a variable missing from the model: in these data, women are lighter (60.3 versus 69.4 kg on average) and weight is correlated with response (r = 0.39).
The Wald P values (0.0085 and 0.0094) are much larger than those of the likelihood ratio tests obtained by comparing nested models: G² is 26.81 with Age and Sex, 12.33 with Age alone and 4.435 with Sex alone, hence χ² = 26.81 − 12.33 = 14.48 for Sex (1 df, P = 0.00014) and χ² = 26.81 − 4.435 = 22.38 for Age (1 df, P = 2.2 × 10⁻⁶). The Hosmer-Lemeshow test detects no lack of calibration, but with 40 subjects it has little power.
Reporting the results#
"In a multiple logistic regression (n = 40, 12 responders), response was associated with age (OR 1.40 per year; 95% CI 1.09 to 1.81) and sex (OR women/men 0.007; 95% CI 0.0002 to 0.30), each adjusted for the other (likelihood ratio tests: P < 0.0001 for age, P = 0.00014 for sex). The model was globally significant (G² = 26.8, 2 df, P < 0.0001), with no lack of calibration detected (Hosmer-Lemeshow H = 6.04, 8 df, P = 0.64); area under the ROC curve 0.93, not validated on an independent sample."
Always give the number of events, the list of the variables in the model and the reference level of categorical variables.
Common pitfalls#
- Too few events per variable: with fewer than about ten events per coefficient, the odds ratios are unstable and often exaggerated, as in the example.
- Wald tests for strong effects: when a coefficient is large, its standard error grows faster than it does and the Wald test loses power. Variance gives the likelihood ratio only for the whole model; for one variable, fit the model with and without it and take the difference of the G² (same set of subjects), to be compared with a χ² distribution whose df is the number of coefficients removed.
- Separation: a variable, or a level of a categorical variable, that predicts the outcome perfectly gives excessive coefficients and CIs; Variance does not display a warning.
- Hosmer-Lemeshow: low power with few subjects; with few distinct values of π̂ (all explanatory variables categorical), the groups are formed by distinct value, the test has few degrees of freedom and is not very informative; with fewer than 3 distinct values, it is not computed.
- Classification table: it depends on the chosen cutoff and the proportion of events; computed on the fitting data, it is optimistic, like the area under the ROC curve.
- Odds ratio ≠ relative risk when the event is common.
- Interactions without centering: as in multiple linear regression, the main effects become effects at the value 0 of the other variable.
References#
Books:
- Motulsky H. Intuitive Biostatistics, 4th ed. Oxford University Press, 2018.
- Motulsky H, Christopoulos A. Fitting Models to Biological Data Using Linear and Nonlinear Regression. Oxford University Press, 2004.
- Zar JH. Biostatistical Analysis, 5th ed. Pearson Prentice Hall, 2010.
- Altman DG. Practical Statistics for Medical Research. Chapman & Hall, 1991.
- Sokal RR, Rohlf FJ. Biometry, 4th ed. W. H. Freeman, 2012.
- Draper NR, Smith H. Applied Regression Analysis, 3rd ed. Wiley, 1998.
- Deming WE. Statistical Adjustment of Data. Wiley, 1943.
- McCullagh P, Nelder JA. Generalized Linear Models, 2nd ed. Chapman & Hall, 1989.
- Cox DR, Snell EJ. Analysis of Binary Data, 2nd ed. Chapman & Hall, 1989.
- Agresti A. Categorical Data Analysis, 3rd ed. Wiley, 2013.
- Hosmer DW, Lemeshow S, Sturdivant RX. Applied Logistic Regression, 3rd ed. Wiley, 2013.
Articles:
- Spearman C. The proof and measurement of association between two things. American Journal of Psychology 1904;15:72-101.
- Fisher RA. On the "probable error" of a coefficient of correlation deduced from a small sample. Metron 1921;1:3-32.
- Wald A, Wolfowitz J. On a test whether two samples are from the same population. Annals of Mathematical Statistics 1940;11:147-162.
- Cornbleet PJ, Gochman N. Incorrect least-squares regression coefficients in method-comparison analysis. Clinical Chemistry 1979;25:432-438.
- Linnet K. Evaluation of regression procedures for methods comparison studies. Clinical Chemistry 1993;39:424-432.
- Bland JM, Altman DG. Statistical methods for assessing agreement between two methods of clinical measurement. Lancet 1986;1:307-310.
- Nelder JA, Wedderburn RWM. Generalized linear models. Journal of the Royal Statistical Society A 1972;135:370-384.
- Hurvich CM, Tsai CL. Regression and time series model selection in small samples. Biometrika 1989;76:297-307.
- Hauck WW, Donner A. Wald's test as applied to hypotheses in logit analysis. Journal of the American Statistical Association 1977;72:851-853.
- Hosmer DW, Lemeshow S. Goodness of fit tests for the multiple logistic regression model. Communications in Statistics – Theory and Methods 1980;9:1043-1069.
- McFadden D. Conditional logit analysis of qualitative choice behavior. In: Zarembka P (ed.). Frontiers in Econometrics. Academic Press, 1974:105-142.
- Nagelkerke NJD. A note on a general definition of the coefficient of determination. Biometrika 1991;78:691-692.
- Tjur T. Coefficients of determination in logistic regression models: a new proposal, the coefficient of discrimination. The American Statistician 2009;63:366-372.
- Hanley JA, McNeil BJ. The meaning and use of the area under a receiver operating characteristic (ROC) curve. Radiology 1982;143:29-36.
- Peduzzi P, Concato J, Kemper E, Holford TR, Feinstein AR. A simulation study of the number of events per variable in logistic regression analysis. Journal of Clinical Epidemiology 1996;49:1373-1379.