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:

cov(x, y) = Σ[(x_i - x̄)(y_i - ȳ)] / (n - 1)

The sample standard deviation is:

s_x = √[Σ (x_i - x̄)² / (n - 1)]

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 = cov(x, y) / (s_x × s_y)

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.

Scatter plot of five observations The horizontal axis is the observation index 0 to 5 at 60 pixels per unit; the vertical axis is value 1 to 5 at 32 pixels per unit, with dashed gridlines labelled 2 to 5 at the left. The five points are (1,2), (2,4), (3,5), (4,4) and (5,5), rising left to right to show a positive linear association; with only five observations the figure is for demonstration and cannot support inference. 0 1 2 3 4 5 1 2 3 4 5 x (observation index) y
Figure 1: scatter plot of the five-observation sample; sample covariance 1.5 and correlation about 0.77. The points are a teaching example, useful for direction and shape but not for population inference or causal conclusions.

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. r measures 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

  1. Align observations and units; inspect missing values and outliers.
  2. Compute means, deviations and cross-products.
  3. Choose n - 1 or n as the denominator and state it.
  4. Compute covariance, both standard deviations and the correlation.
  5. Plot the data and inspect nonlinearity, outliers and range.
  6. 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.

Covariance and Correlation: mechanism chain Covariance and Correlation — three-step structure: problem, mechanism, judgment. Labels come from the article's sections, not new data. Covariance and Correlation: mechanism chain Labels come from the article's sections; all three steps matter. Problem Covariance and correlation… Covariance and correlation describe linear co-movement. Reproduction Reproduction: 1. Reproduction: 1. Data Five observations (purely illustra… Five observation s (purely illustrative, not a real statistical… Reading order: test the problem, then the mechanism, then whether the judgment overreaches. If a middle step lacks evidence, later conclusions are hypotheses, not facts. Structural illustration, not a new data chart; sample is the article's own argument.
Figure 2: Covariance and Correlation — mechanism chain: problem, mechanism, judgment. Sample: the article's own argument; units as stated in the text.
Covariance and Correlation: boundary Separates conditions where the claim holds from those where it fails; a local example is not universal. Covariance and Correlation: when does it hold? Check the conditions before the conclusion If conditions, definitions or samples change, recompute the conclusion Holds Small samples. Fails / rewrite What does it mean for two variables to move together? Boundary illustration; sample is the article's own argument; units as stated in the text.
Figure 3: Covariance and Correlation — boundary: when the claim holds, and when it fails. Sample: the article's own argument; units as stated in the text.
Covariance and Correlation: object, conditions and common mistakes Three rows compare the concept, its conditions and common mistakes; comparison is not equivalence and does not replace a definition. Covariance and Correlation: object, conditions and common mistakes at a glance This article Commonly confused Object Covariance and correlation describe… Adjacent concepts / common claims Conditions Small samples. What does it mean for two variables to move together?… Check Define first, then compare; never judge labels only Correlation is not causation; a local case is not universal Comparison illustration; sample is the article's own argument; units as stated in the text.
Figure 4: Covariance and Correlation — comparison of object, conditions and common mistakes. Sample: the article's own argument; units as stated in the text.

Exercises

  1. Degenerate case. If all y values are identical, what is the covariance? Can the correlation be calculated?
  2. 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?
  3. Causal judgment. Ice-cream sales and drowning deaths are positively correlated. Does ice cream cause drowning? What alternatives should be considered?
Suggested answers
  1. All y are equal, so y_i - ȳ = 0 and covariance is zero; s_y = 0, so the correlation denominator is zero and r is undefined. Report “not computable,” not zero.
  2. 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.
  3. 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

  1. 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)
  2. 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)
  3. 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.

Sample r—
Sample covariance—
Regression slope—

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.

Back to station