Written and maintained by CASRAI Editorial Board
Last updated
fitted() in R returns the values a fitted model predicts for the observations it was built from. Give it the object returned by lm() or glm() and you get one fitted value per observation used in the fit. fitted.values() is an alias for the same function. The sections below show the call, how it differs from predict(), what happens to missing values, and which scale a glm reports on.
What fitted() is used for in research
Fitted values are the model’s own predictions for the data it was estimated on. Researchers extract them to plot observed against predicted outcomes, to compute residuals, and to check a regression’s assumptions (see assumptions of simple regression and how to read a residual plot). The R documentation describes fitted as a generic function that extracts fitted values from objects returned by modeling functions, and says every class of object returned by a model-fitting function should provide a fitted method.
In statistics notation the fitted value for each observation is usually written as y-hat. For the difference between observed and fitted values, see how to calculate residuals.
Install or access
fitted belongs to the stats package that ships with R, so no extra package is needed. R itself is distributed from the Comprehensive R Archive Network (CRAN); the binary installers for Linux, macOS and Windows are listed at cran.r-project.org/bin/. The help page for the function is at stat.ethz.ch/R-manual/R-devel/library/stats/html/fitted.values.html, and inside R you can open it with ?fitted.
Step-by-step: get fitted values from a model
The usage on the help page is fitted(object, ...) and fitted.values(object, ...). The steps below apply it to a linear model.
- Fit a model.
fit = lm(y ~ x, data = mydata)Replace
y,xandmydatawith your own response, predictor and data frame. - Extract the fitted values.
fitted(fit)The result holds the fitted values extracted from the object you passed.
- Use the alias if you prefer it.
fitted.values(fit)The help page states that
fitted.valuesis an alias forfitted. Note that the generic isfitted, notfitted.values. - Read them from the model object.
fit$fitted.valuesThe
lmhelp page listsfitted.valuesamong the components of the returned object (described as the fitted mean values) and namesfitted.valuesamong the generic accessor functions forlmresults. - Add them to your data frame. Only do this when no rows were dropped for missing values (see the troubleshooting section):
mydata$fit = fitted(fit) - Get the matching residuals.
residuals(fit)The
lmhelp page defines the residuals as the response minus the fitted values.residis an alias forresiduals.
Output and how to read it
Fitted values versus predict()
For a model fitted with lm, predict(fit) without newdata returns predictions based on the data used for the fit, which is the same thing fitted(fit) reports. The documentation for predict.lm states: “If newdata is omitted the predictions are based on the data used for the fit.” Choose predict() when you need more than the in-sample values. Its usage includes newdata, se.fit, interval (none, confidence or prediction), level (default 0.95) and type. With an interval requested, the result is a matrix with columns fit, lwr and upr. With se.fit = TRUE it is a list containing fit, se.fit, residual.scale and df.
The same help page separates the two interval types: a confidence interval is for the mean response, a prediction interval is for a single future observation.
Fitted values from a glm: link scale or response scale
For a generalized linear model the choice of scale matters. predict.glm has a type argument whose default is link, which gives predictions on the scale of the linear predictors; for a binomial model with the usual logit link that means log-odds. Setting type = 'response' returns values on the scale of the response variable, such as probabilities. type = 'terms' returns a matrix of fitted values for each term, on the linear-predictor scale. To avoid ambiguity in a report, state the scale explicitly:
predict(fit_glm, type = "response")
For background on this model family, see what is a generalized linear model.
Missing values
The fitted help page says that methods can use napredict to compensate for the omission of missing values, and that the default and nls methods do. The predict.lm page spells out the consequence when newdata is omitted: the na.action used in the fit controls missing values. With na.omit the omitted cases are absent from the result; with na.exclude they appear as NA. If you want fitted values and residuals that line up row for row with your original data, fit the model with na.action = na.exclude; the lm help page notes that na.exclude can be useful.
Troubleshooting
- Assigning the fitted values to a column fails because the lengths differ. The model dropped incomplete cases (the
lmdefaultna.actionisna.omit), so the fitted vector is shorter than the data frame. Refit withna.action = na.excludeor filter the data to complete cases first. - Values look like log-odds, not probabilities. You are on the
linkscale, the default forpredict.glm. Requesttype = 'response'. - Predictions for new observations come back with the original length.
predict()only uses new data when you passnewdata. Without it, predictions are based on the data used for the fit.
Free alternatives and equivalent calls in R
Within R there are several ways to obtain the same in-sample values or to go further. Each row below is taken from the R documentation pages listed in the sources.
| Call | What it returns | Documented on |
|---|---|---|
fitted(fit) |
Fitted values extracted from the model object | fitted help page |
fitted.values(fit) |
Alias for fitted |
fitted help page |
fit$fitted.values |
The fitted mean values stored in an lm object |
lm help page |
predict(fit) |
Predictions based on the data used for the fit when newdata is omitted |
predict.lm help page |
predict(fit, newdata = d, interval = 'prediction') |
Matrix with fit, lwr, upr for new observations |
predict.lm help page |
predict(fit_glm, type = 'response') |
Predictions on the scale of the response variable | predict.glm help page |
residuals(fit) |
Response minus fitted values for an lm |
lm help page |
FAQ
What does fitted() do in R?
It extracts fitted values from the object returned by a model-fitting function such as lm or glm. fitted.values is an alias.
Is fitted() the same as predict()?
For an lm, predict(fit) without newdata is based on the data used for the fit, so it carries the same meaning as fitted(fit). predict() adds newdata, intervals and standard errors.
How do I add fitted values to a data frame in R?
Assign them to a new column, for example mydata$fit = fitted(fit), after checking that the model did not drop rows. If it did, refit with na.action = na.exclude or use only complete cases.
How do I get fitted values on the probability scale for a logistic regression?
Use predict(fit_glm, type = 'response'). The default type = 'link' returns log-odds for a binomial model.
What is the difference between fitted values and residuals?
The lm help page describes residuals as the response minus the fitted values. Fitted values are the model’s predictions; residuals are what the model leaves unexplained. For worked residual diagnostics see the Breusch-Pagan test in R.
Sources (official documentation)
Date checked: 2026-10-29. All links go to the official documentation.
- R Core Team, fitted: Extract Model Fitted Values, R documentation, stats package.
- R Core Team, predict.lm: Predict method for Linear Model Fits, R documentation, stats package.
- R Core Team, predict.glm: Predict Method for GLM Fits, R documentation, stats package.
- R Core Team, lm: Fitting Linear Models, R documentation, stats package.
- R Core Team, residuals: Extract Model Residuals, R documentation, stats package.
- The Comprehensive R Archive Network, binary distributions index.








