Research question
What does it mean for two variables to move together? If unemployment rises while inflation falls, does unemployment cause the change in inflation? This article defines covariance and correlation, explains what they can and cannot answer, and demonstrates the calculation with a small sample. The conclusion is descriptive only; it is not a causal or forecasting claim.
Data
Five observations (purely illustrative, not a real statistical series):
| Observation | x | y |
|---|---|---|
| 1 | 1 | 2 |
| 2 | 2 | 4 |
| 3 | 3 | 5 |
| 4 | 4 | 4 |
| 5 | 5 | 5 |
Requirements: x and y must be aligned on the same observation unit; there are no missing values; the sample is tiny. For a time series, first confirm frequency, common period, seasonal adjustment and revision vintage; never pair series with different definitions.
A scatter plot is used to inspect the relationship between two variables and to check shape and outliers before computing a regression or a correlation, the step OpenStax recommends [2].
Method and formulas
The sample covariance measures whether two variables deviate from their means in the same direction:
The sample standard deviation is:
Covariance carries the product of the two variables’ units (for example “percentage points × percentage points”), so its magnitude depends on scale and is hard to compare across pairs; the correlation coefficient standardizes covariance and removes units:
r ranges from -1 to 1. Its sign gives the linear direction, and its absolute value gives the strength of linear association. r = 0 means no linear association; it does not mean the variables are independent. Using n - 1 or n changes covariance and standard deviations (in this article's worked example, covariance moves from 1.5 to 1.2 and the standard deviations scale the same way) but not the correlation: both routes give r = 0.7746 because numerator and denominator scale together; the denominator used must still be reported. That invariance is recomputed here from the article's own worked example, not quoted from an external source.
The correlation coefficient r measures the strength and direction of the linear relationship between x and y, and the null hypothesis tested is that the population correlation is zero — the OpenStax framing [1].
Results
The means are x̄ = 3 and ȳ = 4. The deviations and cross-products are:
| x | y | x - x̄ | y - ȳ | Product |
|---|---|---|---|---|
| 1 | 2 | -2 | -2 | 4 |
| 2 | 4 | -1 | 0 | 0 |
| 3 | 5 | 0 | 1 | 0 |
| 4 | 4 | 1 | 0 | 0 |
| 5 | 5 | 2 | 1 | 2 |
| Sum | 0 | 0 | 6 |
Therefore:
- sample covariance
cov = 6 / 4 = 1.5; s_x = √(10 / 4) ≈ 1.5811;s_y = √(6 / 4) ≈ 1.2247;- correlation
r = 1.5 / (1.5811 × 1.2247) ≈ 0.7746.
In this five-observation sample, x and y have a positive linear association of moderate-to-high strength. The number is not a reliable estimate of a population correlation, and it does not show that changes in x cause changes in y.
The sample covariance is the sum of cross-products of deviations divided by n−1; the cov = 6 / 4 line in this article is that formula with the teaching numbers substituted (NIST/SEMATECH handbook) [3].
Robustness and failure conditions
- Small samples. Five points can be changed by one observation; do not estimate a population relationship from them. Rolling time-series correlations should report the window and the number of valid pairs; this site’s formal charts will not display a coefficient with fewer than 12 valid pairs.
- Outliers. A single extreme value can move covariance and correlation substantially; inspect the raw series and measurement definitions instead of deleting points automatically.
- Nonlinearity.
rmeasures linear association only. A clear U-shaped relationship can produce a coefficient near zero even when the variables are not independent. - Restricted range. Observing only a narrow interval can lower the correlation and does not justify extrapolation.
- Common sample and frequency. Both series need the same period and frequency; mismatched frequencies, missing values and revisions can create false pairs.
- Trends and spurious correlation. Two series that both rise over time can correlate strongly without a direct mechanism; detrend, difference or use an explicit research design.
- Selection and confounding. How observations enter the sample and which variables are omitted and whether a common cause exists can change the interpretation.
- Multiple attempts. Trying many periods, transformations and indicators and reporting only the strongest result overstates the evidence.
Limitations
The sample has only five observations and is constructed for teaching; there is no sampling design, population inference or control for confounding. Correlation analysis does not establish causal direction, predict the future or show stability. A real study needs documented data sources, sample period, frequency, missing-data rules and a research design, with alternative specifications and failed checks reported.
Reproduction
- Align observations and units; inspect missing values and outliers.
- Compute means, deviations and cross-products.
- Choose
n - 1ornas the denominator and state it. - Compute covariance, both standard deviations and the correlation.
- Plot the data and inspect nonlinearity, outliers and range.
- Report sample size, valid pairs, period and transformations; do not report only
r.
Pseudocode:
mx = mean(x)
my = mean(y)
cov = sum((x[i] - mx) * (y[i] - my)) / (n - 1)
r = cov / (sd(x, n - 1) * sd(y, n - 1))
Strength of conclusions
The defensible statement is: in these five teaching observations, x and y have a positive linear association (r ≈ 0.7746). Population correlation, causation, predictive power and statistical significance are not supported. A significance test requires its own assumptions and cannot repair a weak sample design or identification problem.
Related
- Required prerequisite: Probability Distributions, Expectation and Variance (RES-009).
- Related reading: Data Units and Statistical Definitions (RES-001), Probability Distributions, Expectation and Variance (RES-009), Introduction to Linear Regression (RES-013).
Figures in plain language
The three figures below check the mechanism, boundary and comparison in this article; labels come from its own sections, not new data.
Exercises
- Degenerate case. If all y values are identical, what is the covariance? Can the correlation be calculated?
- Nonlinearity. Let x = -2, -1, 0, 1, 2 and y = x². y clearly depends on x; what is the correlation approximately, and what does that show?
- Causal judgment. Ice-cream sales and drowning deaths are positively correlated. Does ice cream cause drowning? What alternatives should be considered?
Suggested answers
- All y are equal, so
y_i - ȳ = 0and covariance is zero;s_y = 0, so the correlation denominator is zero andris undefined. Report “not computable,” not zero. - With mean x = 0 and mean y = 2, the cross-products sum to zero, so covariance and correlation are both zero. y is completely determined by x, yet the linear correlation is zero; always inspect the scatter plot and nonlinearity.
- No. Common explanations include weather or season, more people near water, sample selection and reporting bias. Correlation alone cannot distinguish these mechanisms; additional identification is needed.
Sources
- Illowsky, Barbara, and Susan Dean. Introductory Statistics 2e, “12.4 Testing the Significance of the Correlation Coefficient.” OpenStax. CC BY-NC-SA 4.0. https://openstax.org/books/introductory-statistics-2e/pages/12-4-testing-the-significance-of-the-correlation-coefficient (accessed 2026-10-30)
- Illowsky, Barbara, and Susan Dean. Introductory Statistics 2e, “12.2 Scatter Plots.” OpenStax. CC BY-NC-SA 4.0. https://openstax.org/books/introductory-statistics-2e/pages/12-2-scatter-plots (accessed 2026-10-30)
- NIST/SEMATECH. e-Handbook of Statistical Methods, “6.5.4.1 Mean Vector and Covariance Matrix.” https://www.itl.nist.gov/div898/handbook/pmc/section5/pmc541.htm (accessed 2026-10-30)
Worked demo
In a scatter plot, r is just one number
Set the direction and strength of correlation, then change the sample size. A small sample makes r jump and the cloud shift; correlation is not causation.
The points are a teaching sample generated from the chosen ρ, not real data; correlation is not causation.
Scatter and fitted line
The numbers are teaching assumptions that show relationships, not forecasts or investment advice.
This article has passed the current publication gate. Factual, calculation and translation revisions update both language versions together.