Skip to main content
v2026.11,858 entries · CC-BY 4.0

Sum of Squares Formula: SST, SSR and SSE Explained

The sum of squares formula for SST, SSR and SSE, worked both ways on one dataset, with naming traps across NIST, OpenStax and statsmodels.

Written and maintained by CASRAI Editorial Board

Last updated

The sum of squares is the total of squared distances: add up the squares of some set of numbers. In statistics the phrase almost always means the sum of squared deviations from the mean, written SS or SST, and it is the raw material for variance, standard deviation, analysis of variance and R-squared. This guide gives the formulas, one dataset worked two ways (a regression partition and a one-way ANOVA partition), a table of the naming differences that trip people up, and a reporting example.

What is sum of squares?

Sum of squares is the sum of the squares of a set of values. Two different quantities share the name, and the formulas below separate them:

  • Raw (uncorrected) sum of squares: square each value and add them, Σyi².
  • Corrected, or total, sum of squares: square each value’s distance from the mean and add them, Σ(yi − ȳ)². The NIST/SEMATECH e-Handbook of Statistical Methods calls the numerator of the sample variance the sum of squares of deviations from the mean, also called the corrected sum of squares and abbreviated Total SS or SS(Total).

Dividing the corrected sum of squares by n − 1 gives the sample variance, s² = Σ(yi − ȳ)² / (n − 1); its square root is the standard deviation.

Sum of squares formula

Total sum of squares (SST)

SST = Σ(yi − ȳ)², where yi is the i-th observation, ȳ is the mean of all n observations, and the sum runs over i = 1 to n.

A shortcut form, which NIST calls the raw sum of squares minus the “correction term for the mean”, gives the same number: SST = Σyi² − (Σyi)² / n. OpenStax Introductory Statistics 2e writes the same identity as SStotal = Σx² − (Σx)²/n.

The partition: explained plus unexplained

For a regression with an intercept, the total splits into a part the model accounts for and a part it does not:

  • SST = SSR + SSE
  • SSR (regression, or explained, sum of squares) = Σ(ŷi − ȳ)², where ŷi is the fitted value.
  • SSE (error, or residual, sum of squares) = Σ(yi − ŷi)².
  • R² = SSR / SST = 1 − SSE / SST.

One-way ANOVA partition

With k groups, ni observations in group i and N observations overall, NIST gives SS(Total) = SST + SSE, with the group (treatment) part Σ ni(ȳi − ȳ)² and the error part ΣiΣj(yij − ȳi)². OpenStax calls these SSbetween and SSwithin, with MSbetween = SSbetween / (k − 1) and MSwithin = SSwithin / (n − k).

Worked example: one dataset, two partitions

Regression partition

Six students record hours studied (x) and exam score (y). This is an illustrative dataset made up for the calculation.

Hours (x) Score (y) y − ȳ (y − ȳ)² Fitted ŷ y − ŷ
1 52 −13.5 182.25 51.571 0.429
2 58 −7.5 56.25 57.143 0.857
3 61 −4.5 20.25 62.714 −1.714
4 69 3.5 12.25 68.286 0.714
5 72 6.5 42.25 73.857 −1.857
6 81 15.5 240.25 79.429 1.571
  1. Mean: Σy = 393, so ȳ = 393 / 6 = 65.5.
  2. SST: 182.25 + 56.25 + 20.25 + 12.25 + 42.25 + 240.25 = 553.5.
  3. Check with the shortcut: Σy² = 26,295 and (Σy)²/n = 393²/6 = 25,741.5, so SST = 26,295 − 25,741.5 = 553.5. The raw sum of squares (26,295) and the corrected one (553.5) are very different numbers; the gap is the correction term for the mean.
  4. Least-squares line: slope = 97.5 / 17.5 = 5.5714 and intercept = 65.5 − 5.5714 × 3.5 = 46.0, so ŷ = 46.0 + 5.5714x.
  5. SSE: the squared residuals are 0.184, 0.735, 2.939, 0.510, 3.449 and 2.469, which sum to 10.286.
  6. SSR = SST − SSE = 553.5 − 10.286 = 543.214. Computed directly from Σ(ŷ − ȳ)² it gives the same value.
  7. R² = 543.214 / 553.5 = 0.981.

One-way ANOVA partition

Take twelve scores from three groups of four (again illustrative): Group A = 52, 58, 61, 69; Group B = 72, 81, 64, 70; Group C = 55, 60, 66, 63. The group means are 60, 71.75 and 61; the grand mean is 771 / 12 = 64.25.

  • SSbetween = 4(60 − 64.25)² + 4(71.75 − 64.25)² + 4(61 − 64.25)² = 72.25 + 225 + 42.25 = 339.5.
  • SSwithin = 150 + 148.75 + 66 = 364.75 (the squared deviations inside groups A, B and C).
  • SStotal = 339.5 + 364.75 = 704.25, which matches summing (y − 64.25)² over all twelve scores.
  • dfbetween = k − 1 = 2 and dfwithin = n − k = 9, so MSbetween = 169.75, MSwithin = 40.53 and F = 169.75 / 40.53 = 4.19, p = .052.

Interpretation

A sum of squares has no natural scale on its own: it grows with the number of observations and with the square of the measurement unit. It becomes interpretable as a share of the total or after dividing by degrees of freedom.

Result What it says In the examples
SSE / SST near 0 The fitted values sit close to the data; R² near 1 10.286 / 553.5 = 0.019, so R² = 0.981
SSR / SST near 0 The model explains little beyond the mean Not the case in the regression example
SSbetween / SStotal Share of variability attributable to group membership (eta-squared) 339.5 / 704.25 = 0.482
SSwithin / dfwithin Average spread inside groups (MSwithin), the denominator of F 364.75 / 9 = 40.53

The F ratio of mean squares is covered in how to interpret the F-statistic, and the model-fit reading of SSR/SST in how to interpret R-squared. For the difference between eta-squared and partial eta-squared, see eta-squared vs partial eta-squared. Note the ANOVA example: an eta-squared of 0.48 sits beside p = .052, so a large share of variability does not by itself make the F test significant when groups are this small.

Assumptions and common mistakes

  • Mixing up raw and corrected sums. Σy² (26,295 above) is not SST (553.5). Spreadsheets and calculators expose both; use the corrected one for variance and partitions.
  • Expecting SST = SSR + SSE without an intercept. The partition above is for models that include a mean or intercept term. statsmodels reports both a centered total sum of squares (about the mean) and an uncentered one, and R-squared depends on which is used.
  • Reading “SSR” the same in every source. Naming differs, as the table shows. In statsmodels, ssr is the sum of squared residuals, which many regression texts call SSE.
  • Comparing sums of squares across datasets of different size. Compare ratios or mean squares instead.
  • Ignoring the model’s assumptions. The sums are arithmetic and always computable. The F test built on them assumes independent observations, roughly normal errors and similar variance across groups.

Naming differences between sources

Source Total Explained / between groups Unexplained / within groups
NIST/SEMATECH e-Handbook, one-way ANOVA SS(Total) SST (treatments) SSE
OpenStax Introductory Statistics 2e SStotal SSbetween SSwithin
statsmodels RegressionResults centered_tss (about the mean) or uncentered_tss ess, the explained sum of squares ssr, the sum of squared residuals

Note that NIST’s SST means the treatment sum of squares, while this page and most regression material use SST for the total. Always check the definition before comparing output.

How to report it

Sums of squares are usually shown in an ANOVA table, while the text reports the test statistic, degrees of freedom, exact p value and an effect size. The two examples above could be written up as follows:

  • ANOVA: A one-way ANOVA found no significant difference among the three groups, F(2, 9) = 4.19, p = .052, η² = .48.
  • Regression: Hours studied predicted exam score, F(1, 4) = 211.25, p < .001, R² = .98.

How to calculate sum of squares in Excel, R or Python

Excel

=SUMSQ(B2:B7)            raw sum of squares: 26295
=DEVSQ(B2:B7)            corrected sum of squares (SST): 553.5
=INDEX(LINEST(B2:B7,A2:A7,TRUE,TRUE),5,1)   SSR: 543.214
=INDEX(LINEST(B2:B7,A2:A7,TRUE,TRUE),5,2)   SSE: 10.286

R

x <- 1:6; y <- c(52,58,61,69,72,81)
sum((y - mean(y))^2)     # SST = 553.5
anova(lm(y ~ x))         # "Sum Sq" column: x = 543.21, Residuals = 10.29

Python

import numpy as np, statsmodels.api as sm
x = np.arange(1, 7); y = np.array([52,58,61,69,72,81])
m = sm.OLS(y, sm.add_constant(x)).fit()
print(m.centered_tss)   # SST 553.5
print(m.ess)            # explained SS 543.21
print(m.ssr)            # residual SS 10.29 (statsmodels names this ssr)

For a worked statsmodels ANOVA table, see ANOVA in Python with statsmodels.

FAQ

What is the formula for the sum of squares?

For deviations from the mean it is SST = Σ(yi − ȳ)², equivalently Σyi² − (Σyi)²/n. The plain sum of squares of the values is Σyi².

What is the difference between SST, SSR and SSE?

SST is total variability around the mean, SSR the part explained by the regression and SSE the residual part, with SST = SSR + SSE. Source naming varies, so check the definition (see the naming table above).

Can a sum of squares be negative?

No. Every term is a square, so each is zero or positive. A negative value in output points to a different quantity or a calculation error.

How does sum of squares relate to variance?

The sample variance is the corrected sum of squares divided by n − 1.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Sum of Squares Formula: SST, SSR and SSE Explained

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Ask CASRAI · Regulatory Radar

Research-admin question? Get an answer that links its sources.

An AI assistant specialized in research administration. Every answer links its sources to check before you act. 2 questions free, no account. $29/month after.

  • Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.
  • Every answer numbers its sources and links each one, so you can check the source yourself.