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

Y Hat (ŷ): Meaning, Formula and Worked Example

Y hat (ŷ) is the predicted value of y from a regression line. See the formula, a worked example, how it differs from y and y bar, and how to report it.

Written and maintained by CASRAI Editorial Board

Last updated

Y hat (written ŷ) is the value of y that a fitted regression line predicts for a given x. It is not an observed measurement: it is the point on the line directly above or below an observation, and the gap between the observed y and ŷ is that observation’s residual. This guide defines ŷ, shows the formula, works one example by hand with the arithmetic visible, and gives Excel, R and Python code for getting the same numbers.

What does y hat (ŷ) mean?

ŷ is the estimated value of y, obtained by putting an x value into the regression line. OpenStax Introductory Statistics 2e describes it as “the estimated value of y. It is the value of y obtained using the regression line.” The hat marks an estimate. NIST/SEMATECH uses the same device for fitted parameters, placing a hat on estimators “to emphasize the fact that the estimators are not the same as the true values of the parameters.” So y is what you measured, ŷ is what the model says, and ȳ (y bar) is the mean of all the measured y values. Three different quantities, three different symbols.

Y hat formula

For simple linear regression with one predictor, the line is:

ŷ = a + bx

  • ŷ: the predicted (fitted) value of y for a given x.
  • x: the value of the predictor variable you put into the line.
  • a: the intercept, a = ȳ − b·x̄ (the line is anchored through the point of the two means).
  • b: the slope, b = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)².
  • x̄, ȳ: the means of the observed x and y values.

These are the formulas in OpenStax 12.3, The Regression Equation. For a model that is not a straight line, the same idea holds. NIST/SEMATECH writes the residual as ei = yi − f(xi; β̂), where f(xi; β̂) is the regression function evaluated with the estimated parameters. That function value is the fitted value, written ŷi in this guide. For how the slope is built and read, see what a regression coefficient is.

Worked example: predicting a final exam score

OpenStax 12.3 fits a line to third-exam scores (x) and final-exam scores (y) and reports:

ŷ = −173.51 + 4.83x

One student scored x = 65 on the third exam and y = 175 on the final. Step by step:

  1. Substitute: ŷ = −173.51 + 4.83 × 65.
  2. Multiply: 4.83 × 65 = 313.95.
  3. Add: 313.95 − 173.51 = 140.44. So ŷ = 140.44.
  4. Residual = y − ŷ = 175 − 140.44 = 34.56.

The line predicts about 140 for this student, who actually scored 175. The residual is positive because the actual score sits above the line. OpenStax notes that the absolute value of a residual “measures the vertical distance between the actual value of y and the estimated value of y.” The full residual workflow is in how to calculate residuals.

Interpretation: what ŷ and the residual tell you

What you see What it means
ŷ = 140.44 at x = 65 The value of y the line gives for x = 65. It is a model output, not a measurement.
Residual y − ŷ is positive (34.56) The observed y is above the line (OpenStax).
Residual y − ŷ is negative The observed y is below the line, because the residual is observed minus predicted.
Residual is 0 The observed point lies exactly on the line.
Absolute value of the residual The vertical distance from the point to the line (OpenStax).

Plotting y against x with the line drawn through it makes this visible: each ŷ is on the line, each y is a dot, and each residual is the vertical gap. See scatterplot interpretation for reading that picture. The squared gaps are the raw material of the sum of squares and, through it, of the coefficient of determination.

Assumptions and common mistakes

  • Treating ŷ as data. ŷ comes from the fitted line and changes whenever a and b change. Refit on different data and every ŷ moves. Report observed values as y and model values as ŷ.
  • Flipping the residual sign. The residual is y − ŷ (observed minus predicted), as in the NIST definition. Computing ŷ − y gives the opposite sign and reverses “above the line” and “below the line.”
  • Mixing up ŷ and ȳ. ȳ is one number for the whole data set. ŷ is a different number for each x.
  • Rounding the coefficients first. The hand calculation above uses a and b rounded to two decimals. Software carries more digits, so its ŷ can differ from yours in the last decimals. Compute from the unrounded coefficients when precision matters.
  • Using the wrong model. The formula ŷ = a + bx assumes a straight-line relationship between one predictor and y. With a curved or multi-predictor model, ŷ is f(x; β̂) from that model, not a + bx.

How to report it (APA example)

The APA Style numbers and statistics guide (7th edition handout, last updated September 11, 2024) sets these relevant rules: put a space before and after a mathematical operator, but for a negative value put a space only before the minus sign; use italics for letters used as statistical symbols or algebraic variables; and put a zero before the decimal point when the statistic can exceed 1. Applied to this example:

The regression equation was ŷ = −173.51 + 4.83x, where x is the third-exam score. For a student with a third-exam score of 65, the predicted final-exam score was 140.44, and the residual was 34.56.

Set the x in italics in your manuscript. The handout also says to use the term, not the symbol, for statistics in running text, which is why the sentence above says “predicted final-exam score” and “residual” rather than using a symbol for each.

How to calculate y hat in Excel, R or Python

These snippets use a small illustrative data set built for this page (not real study data): x = 1, 2, 3, 4, 5 and y = 2, 4, 5, 4, 6. By hand, x̄ = 3 and ȳ = 4.2, so b = 8.0 / 10 = 0.8 and a = 4.2 − 0.8 × 3 = 1.8. The line is ŷ = 1.8 + 0.8x, giving fitted values 2.6, 3.4, 4.2, 5.0, 5.8, residuals −0.6, 0.6, 0.8, −1.0, 0.2, and ŷ = 6.6 at x = 6.

Excel

With x in A2:A6 and y in B2:B6, the predicted value at x = 6 is =FORECAST.LINEAR(6, B2:B6, A2:A6), which returns 6.6. Alternatively =INTERCEPT(B2:B6, A2:A6) + SLOPE(B2:B6, A2:A6) * 6. Put each fitted value in column C and use =B2-C2 (y minus fitted) in column D to get each residual.

R

x <- c(1, 2, 3, 4, 5)
y <- c(2, 4, 5, 4, 6)
fit <- lm(y ~ x)
fitted(fit)                          # 2.6 3.4 4.2 5.0 5.8
predict(fit, data.frame(x = 6))      # 6.6
resid(fit)                           # -0.6 0.6 0.8 -1.0 0.2

Python

import numpy as np
x = np.array([1, 2, 3, 4, 5])
y = np.array([2, 4, 5, 4, 6])
b, a = np.polyfit(x, y, 1)           # slope, intercept
y_hat = a + b * x                    # 2.6 3.4 4.2 5.0 5.8
print(a + b * 6)                     # 6.6
print(y - y_hat)                     # -0.6 0.6 0.8 -1.0 0.2

For two paired variables before any model is fitted, see bivariate data.

FAQ

What is y hat in statistics?

It is the predicted value of y from a regression model for a given x, written ŷ. It is the point on the fitted line, not an observed measurement.

What is the difference between y and y hat?

y is the observed value; ŷ is the value the model predicts. Their difference, y − ŷ, is the residual.

What is the difference between y hat and y bar?

ȳ is the mean of all observed y values, a single number. ŷ is the model’s prediction and varies with x.

How do you type ŷ?

It is the letter y with a circumflex (Unicode U+0177). Copy it from this page, or in a word processor’s equation tool apply a “hat” accent to y.

Sources

Follow CASRAI

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

Ask CASRAI · free to try

Ask about Y Hat (ŷ): Meaning, Formula and Worked Example

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.