Statistics tutorial · Chapter 02

Choosing an analysis

16 min read · 14 sections

This chapter helps you go from a scientific question to the Variance analysis that answers it. It does not replace thinking about the experimental design: the right test is chosen before collecting the data, from the question and the structure of the experiment, not from the result obtained. The terms used here (paired, parametric, multiple comparisons…) are explained in the chapter "Principles of statistics".

The questions to ask#

  1. What is the goal? Describe, compare groups, relate two variables, predict, fit a model, measure agreement between methods, assess a diagnostic test, summarize many variables, group individuals.
  2. What is the outcome variable? Continuous quantitative, count, ordinal (score), binary or categorical, time to an event (with censoring).
  3. How many groups or conditions? One group compared with a theoretical value, two groups, three or more, one or several factors.
  4. Are the measurements independent? Or paired (same subject, same experiment, matched pairs), repeated over time, nested (technical replicates within an experimental unit)?
  5. Which distribution? Roughly normal, lognormal (the logarithm is normal), clearly skewed or ordinal; with what sample size?
  6. Which type of table? The structure of the data determines the Variance table type, and hence the analyses offered: the Analyze menu greys out those that do not suit the active table, and the Analysis › Choose an Analysis… dialog ("Analysis") presents them by family, with their description as a tooltip.

From goal to analysis#

GoalTable typeVariance analysis (Analyze menu)
Describe a sampleOne factor, XY, Two factors, Nested, MultivariableDescribe and Explore › Descriptive Statistics
Describe a distributionOne factor, XY, Two factorsDescribe and Explore › Frequency Distribution
Check normalityOne factorDescribe and Explore › Normality Tests
Compare a mean or median with a valueOne factorCompare Groups › One-Sample Tests
Compare two groupsOne factorCompare Groups › Two-Group Comparisons
Compare three or more groupsOne factorCompare Groups › One-Way ANOVA
Two or three factorsTwo factorsCompare Groups › Two-Way ANOVA, Three-Way ANOVA
Two groups, one variable per row (omics)Two factorsCompare Groups › Row-by-Row t Tests
Nested technical replicatesNestedCompare Groups › Nested t Test, Nested One-way ANOVA
Compare proportionsContingencyCompare Groups › Contingency Table Tests
Compare a distribution with an expected oneProportions, One factorDescribe and Explore › Observed vs. Expected Frequencies
Compare survivalSurvivalSurvival › Survival Curves (Kaplan-Meier)
Relate two variablesXY, One factor, MultivariableDescribe and Explore › Correlation
Predict Y from XXYCurves and Regression › Simple Linear Regression, Simple Logistic Regression
Predict with several variablesMultivariableCurves and Regression › Multiple Linear Regression, Multiple Logistic Regression, Cox Proportional Hazards Regression
Fit a curve, a modelXYCurves and Regression › Nonlinear Regression, Standard Curve Interpolation, Smoothing Curve (Spline, LOWESS)
Agreement between two measurement methodsOne factor; XYCompare Groups › Bland-Altman Agreement; Curves and Regression › Deming Regression
Performance of a diagnostic testOne factor; ContingencyCompare Groups › ROC Curve; Contingency Table Tests with "Diagnostic measures (sensitivity, specificity, predictive values)"
Reduce the number of variablesMultivariableDescribe and Explore › Principal Component Analysis (PCA)
Group individualsMultivariableClusters › Hierarchical Clustering, K-means Clustering
Analyze a list of P valuesOne factorDescribe and Explore › Multiple P Values (FDR)
Plan (power)noneTools › Calculators… › "Power and sample size (t test, proportions)" (t test, two proportions); for other designs, Simulate › Random Groups then Monte Carlo Simulation

The analyses of the Prepare Data family (Transform, Normalize, Outlier Detection, Baseline Subtraction and Column Arithmetic…) prepare the data; they do not test anything.

Comparing means or medians#

Decision table#

DesignNormal data (or normal after a logarithm)Non-normal or ordinal data, or extreme values
One group against a theoretical valueone-sample t test ("One sample t test"; "One sample t test on logarithms (ratio)")"Wilcoxon signed rank test"
Two independent groupsunpaired t test; Welch's correction if the SDs may differ; t test on logarithms (ratio of geometric means)Mann-Whitney; Kolmogorov-Smirnov to compare whole distributions
Two paired measurementspaired t test; ratio paired t test ("Lognormal")Wilcoxon signed-rank test (paired)
Three or more independent groupsone-way ANOVA; Brown-Forsythe and Welch if the SDs differ; then multiple comparisonsKruskal-Wallis, then Dunn's test
Three or more paired or repeated conditionsrepeated-measures ANOVA (Geisser-Greenhouse correction); mixed model if values are missingFriedman, then Dunn's test
Two crossed factorstwo-way ANOVA (repeated measures on one or both factors, mixed model)no nonparametric equivalent in Variance
Three factorsthree-way ANOVAno equivalent
Two groups, many variables (one per row)multiple t tests (Welch or common SD), with FDRMann-Whitney per row, with FDR
Technical replicates within unitsnested t test, nested ANOVA (mixed model)no equivalent

The corresponding settings#

Two-Group Comparisons, "Experimental Design" tab:

  • "Experimental design": "Unpaired" or "Paired";
  • "Distribution of the data": "Gaussian: parametric test", "Lognormal: test on logarithms (ratio)" or "Not Gaussian: nonparametric test";
  • "Unpaired parametric test": "Unpaired t test (equal SDs)" or "Welch's t test (unequal SDs)";
  • "Unpaired nonparametric test": "Mann-Whitney test (ranks)" or "Kolmogorov-Smirnov test (distributions)";
  • "First column (A)" and "Second column (B)": the two columns compared (the difference is B − A); "Options" tab: "P value" (two-tailed or one-tailed).

One-Way ANOVA: "Experimental design" ("No pairing (independent groups)" or "Paired or repeated measures (one subject per row)"); "Distribution of the residuals" ("Gaussian: ANOVA", "Lognormal: ANOVA on logarithms", "Not Gaussian: nonparametric test (Kruskal-Wallis / Friedman)"); "Equal SDs assumed" ("Equal SDs: ordinary ANOVA" or "Unequal SDs: Brown-Forsythe and Welch ANOVA"); "RM Design" tab for repeated measures ("Repeated measures: analysis method", "Repeated measures: assume sphericity?"); "Multiple Comparisons" tab (which comparisons and which test).

Decision points#

  • Paired or not: the question is about the design, not the values. If each row of the table corresponds to the same subject, the same experiment or the same pair, the design is paired.
  • Welch: Welch's t test stays valid whether or not the SDs are equal; it loses almost nothing when they are equal. It is the cautious choice when the groups have different sizes.
  • Lognormal: concentrations, titers, ratios or durations are often lognormal; comparing their logarithms amounts to comparing geometric means, and the effect reads as a ratio (for example "2.1 times higher").
  • Nonparametric: prefer it for ordinal scores, bounded data or expected extreme values, not because a normality test is "significant" with very few data. With 3 values per group, Mann-Whitney cannot give P < 0.05.
  • Three groups or more: do not run a series of t tests; use ANOVA and its multiple comparisons (Tukey for all pairs, Dunnett against a control…), or restrict yourself to a few corrected planned comparisons.
  • Summary data: the parametric unpaired t test accepts a table entered as mean, SD and n; the paired and nonparametric tests and one-way ANOVA require the individual values.

Comparing proportions and counts#

SituationAnalysis and setting
One proportion compared with a theoretical value (two categories)Observed vs. Expected Frequencies, "Binomial test (two categories)" (exact binomial test); CI: Tools › Calculators… › "CI of a proportion"
Distribution in k categories compared with an expected distributionObserved vs. Expected Frequencies, "Chi-square goodness of fit"
Two groups, binary outcome (2 × 2 table)Contingency Table Tests: Fisher's exact test (automatic choice for a 2 × 2), relative risk, odds ratio, NNT
More than two groups or outcomes (r × c table)Contingency Table Tests, "Chi-square"
Ordered groups (increasing doses) and binary outcome"Chi-square test for trend" (Cochran-Armitage)
Diagnostic test against a reference2 × 2 table, "Diagnostic measures (sensitivity, specificity, predictive values)"
Binary outcome explained by one or more variablesSimple Logistic Regression, Multiple Logistic Regression
Counts of eventsMultiple Linear Regression with "Poisson (Y is a count)"; nonlinear regression with "Poisson regression"
Paired proportions (same subjects twice)Compare Groups › McNemar's Test (Paired Proportions) (Contingency table of the pairs)

The chi-square test is an approximation: Variance shows a warning when an expected count is below 5; for a 2 × 2 table, Fisher's exact test has no such limit. Contingency tables hold counts (integers), never percentages or means.

Example 1 (sample Contingency table "Treatment and outcome (2×2)"): 15 diseased out of 100 treated versus 32 out of 100 on placebo. Two-sided Fisher's exact test: P = 0.0072; relative risk 0.469 (95% CI 0.271 to 0.810); odds ratio 0.375 (0.188 to 0.749); risk difference −0.17 (−0.282 to −0.053), i.e. an NNT of 5.9. The chi-square test with Yates' correction gives χ² = 7.12 (1 df), P = 0.0076.

Example 2 (sample Proportions table "Distribution of categories", Mendel's peas): 315, 108, 101 and 32 seeds compared with the proportions 9:3:3:1. In Observed vs. Expected Frequencies, enter "Expected values" = 9, 3, 3, 1 (the values are scaled to the total of 556):

expected:  312.75   104.25   104.25   34.75
χ² = 2.25²/312.75 + 3.75²/104.25 + 3.25²/104.25 + 2.75²/34.75
   = 0.0162 + 0.1349 + 0.1013 + 0.2176 = 0.470        df = 4 − 1 = 3
P = 0.925

The observations are consistent with the 9:3:3:1 ratio; this does not prove that the ratio is exact (the CIs of the proportions would say which deviations remain possible).

Comparing survival#

QuestionTableAnalysis
Estimate the survival of one or more groups, compare the curvesSurvival (time, code 1 = event, 0 = censored)Survival Curves (Kaplan-Meier): log-rank (Mantel-Cox), Gehan-Breslow-Wilcoxon, log-rank test for trend (three groups or more), hazard ratio, median survival
Compare the curves pairwiseSurvivalsame analysis, "Compare each pair of curves" with a correction for multiplicity
Account for several variables (age, treatment, stage)MultivariableCox Proportional Hazards Regression

The log-rank test gives the same weight to all times; the Gehan-Breslow-Wilcoxon test gives more weight to early events, when many subjects are still at risk. Choose one of them in advance. Both assume non-informative censoring (the reason for censoring does not depend on the prognosis); the hazard ratio and the Cox model assume proportional hazards.

Relating two variables#

QuestionAnalysis
Two measured variables, no explanatory role, linear relationshipCorrelation, "Pearson (assume Gaussian distribution)"
Monotonic relationship, ordinal data or extreme valuesCorrelation, "Spearman (nonparametric)"
Predict Y from X (X set or measured without notable error)Simple Linear Regression (slope, intercept, comparison of lines)
X and Y both measured with error (method comparison)Deming Regression
Nonlinear relationship described by a modelNonlinear Regression
Smooth curve without a modelSmoothing Curve (Spline, LOWESS)
Binary Y (0/1) as a function of XSimple Logistic Regression

Correlation measures the strength of an association; regression describes how Y varies with X and allows prediction. Neither demonstrates causation, and a significant r can correspond to a weak relationship when n is large (r² gives the fraction of shared variance).

Predicting and explaining with several variables#

Multivariable tables (one row per individual, one column per variable) allow:

  • Multiple Linear Regression: continuous Y ("Least squares") or count ("Poisson (Y is a count)") as a function of several predictors, with optional interactions;
  • Multiple Logistic Regression: binary 0/1 outcome; odds ratios, ROC curve;
  • Cox Proportional Hazards Regression: survival time and event; hazard ratios;
  • Principal Component Analysis (PCA) with "Dependent variable (PCR)": principal component regression when the predictors are highly correlated.

Common rule of thumb: plan at least about ten observations per estimated coefficient (for logistic and Cox regressions, about ten events of the less frequent category); with fewer, the model "learns" the noise and generalizes poorly.

Fitting a curve#

SituationAnalysis
Known model (dose-response, binding, enzyme kinetics, exponential decay…)Nonlinear Regression; "Compare" tab to compare two models ("Extra sum-of-squares F test", AICc) or the data sets
Assay unknowns on a standard curveStandard Curve Interpolation
Straight lineSimple Linear Regression
Smooth without a model, differentiate, integrateSmoothing Curve (Spline, LOWESS); Curve Smoothing, Derivative and Integral
Area under a curve (pharmacokinetics, peaks)Area Under Curve
Plot an equationFunction Curve

See the chapter "Curve fitting".

Agreement, diagnosis, multivariate data#

  • Agreement between two measurement methods: Bland-Altman Agreement (bias and limits of agreement); Deming regression estimates the relationship between methods. A high correlation coefficient does not prove agreement: two methods can be perfectly correlated and differ systematically (Bland and Altman, 1986).
  • Quantitative diagnostic test: ROC Curve ("Control values" and "Patient values" columns); area under the curve, sensitivity and specificity at each threshold.
  • Binary diagnostic test: 2 × 2 table (test in rows, reference in columns) analyzed with "Diagnostic measures (sensitivity, specificity, predictive values)".
  • Reducing dimensions: Principal Component Analysis (PCA) (standardized variables by default; number of components chosen by parallel analysis).
  • Grouping individuals: Hierarchical Clustering (dendrogram, heat map) or K-means Clustering (fixed number of clusters; elbow and silhouette criteria). These are exploratory methods: they always find groups, even in data without structure.

By sample size#

  • Very small n (fewer than 5 to 6 per group): no test can check the assumptions; nonparametric tests cannot reach small P values. Base the choice on prior knowledge (data of the same kind, expected logarithmic scale) and show the individual values.
  • Moderate n (ten to a few dozen): parametric tests are robust to moderate departures from normality if the groups are balanced; extreme values and strong skewness remain a problem.
  • Large n: almost everything becomes "significant"; the size of the effect and its CI become what matters, and normality tests reject unimportant deviations.

Examples of choices#

  • Weight of wild-type and knock-out mice (two groups of different animals): Two-Group Comparisons, "Unpaired", parametric test, Welch's correction if the SDs may differ.
  • Blood pressure of 10 patients before and after treatment: same analysis, "Paired".
  • Viral load (very skewed) in three groups: One-Way ANOVA, "Lognormal: ANOVA on logarithms", Tukey comparisons; the means and their differences are then expressed in log10: 10^difference gives the ratio of geometric means.
  • Pain score from 0 to 10 in two groups: Mann-Whitney.
  • Response to three doses in males and females: Two-Way ANOVA on a Two factors table (doses in rows, sexes in columns), sample table "Two-way ANOVA (3 rows × 2 data sets, triplicates)".
  • Four measurements per animal, three animals per treatment: Nested t Test (Nested table), not a t test on 12 values per group.
  • Expression of 5000 genes in two conditions: Row-by-Row t Tests with FDR (BKY).
  • Proportion of responders in two arms of a trial: Contingency Table Tests; report the risk difference or the relative risk with its CI.
  • Time to relapse with patients lost to follow-up: Survival Curves (Kaplan-Meier); never a t test on the observed times.
  • Concentration of a hormone over time, exponential model: Nonlinear Regression.

When not to run a test#

  • To describe a whole population (all the units of an exhaustive register): there is no sampling uncertainty to assess; describe.
  • To compare the groups at baseline in a randomized trial: by construction the differences are due to chance; a test makes no sense (Altman, 1985). Describe the groups and discuss important imbalances.
  • To "prove" the absence of a difference: a P > 0.05 does not allow it. Set an equivalence margin before the study and run an equivalence test: the "Equivalence margin" of the t test (two one-sided tests, TOST, chapter "Comparing groups"), which amounts to checking that the 90% CI of the difference lies entirely within the margin.
  • When the observations are not independent and the design is not modeled (technical replicates treated as subjects, repeated measures treated as independent groups): fix the structure of the analysis first.
  • For a single experimental unit per group: with n = 1, biological variability cannot be estimated, whatever the number of technical measurements.
  • To pick afterwards the most striking comparison: a test planned after looking at the data no longer has the stated error rate; present it as exploratory or correct for all possible comparisons.
  • When the question is one of estimation (how large is the effect?): the CI answers better than a test.

Common pitfalls#

  • Choosing the test from the results (trying t, then Mann-Whitney, then a transformation): this is P-hacking.
  • Running multiple t tests instead of an ANOVA and multiple comparisons.
  • Analyzing percentages or means in a contingency table.
  • Confusing correlation with agreement, or correlation with causation.
  • Treating technical replicates as independent units (pseudoreplication).
  • Ignoring the pairing, or pairing data that are not paired.
  • Analyzing censored survival times as ordinary values.
  • Concluding that there is no effect from a P > 0.05.

References#

  • Altman DG. Comparability of randomised groups. Journal of the Royal Statistical Society, Series D (The Statistician) 1985;34:125-136.
  • Altman DG. Practical Statistics for Medical Research. Chapman & Hall, 1991.
  • Agresti A. Categorical Data Analysis, 3rd ed. Wiley, 2013.
  • Bland JM, Altman DG. Statistical methods for assessing agreement between two methods of clinical measurement. Lancet 1986;327(8476):307-310.
  • Conover WJ. Practical Nonparametric Statistics, 3rd ed. Wiley, 1999.
  • Hosmer DW, Lemeshow S, Sturdivant RX. Applied Logistic Regression, 3rd ed. Wiley, 2013.
  • Jolliffe IT. Principal Component Analysis, 2nd ed. Springer, 2002.
  • Kaufman L, Rousseeuw PJ. Finding Groups in Data: An Introduction to Cluster Analysis. Wiley, 1990.
  • Kleinbaum DG, Klein M. Survival Analysis: A Self-Learning Text, 3rd ed. Springer, 2012.
  • Lazic SE, Clarke-Williams CJ, Munafò MR. What exactly is 'N' in cell culture and animal experiments? PLoS Biology 2018;16:e2005282.
  • Motulsky HJ. Intuitive Biostatistics, 4th ed. Oxford University Press, 2018.
  • Motulsky HJ, Christopoulos A. Fitting Models to Biological Data Using Linear and Nonlinear Regression. Oxford University Press, 2004.
  • Sokal RR, Rohlf FJ. Biometry, 4th ed. W. H. Freeman, 2012.
  • Zar JH. Biostatistical Analysis, 5th ed. Pearson Prentice Hall, 2010.