Skip to main content
v2026.11,858 entries · CC-BY 4.0
LAC HealthMedical & Research SuppliesReagents, PPE & instruments — chain-of-custody documented.Fast, traceable sourcing built for regulated research environments, from bench consumables to instrumentation.Shop lac.us CodeCASRAIlac.us

Predict in R: predict(), newdata and Intervals

How predict() works in R: newdata, confidence vs prediction intervals for lm, and link vs response scale for glm, with the arguments from the R manual.

Written and maintained by CASRAI Editorial Board

Last updated

predict() is the base R function that turns a fitted model into predictions for new data. Searches for “predict in R”, “predict r” and “r predict” all land on the same function: a generic in the stats package that hands the work to a method chosen by the class of the model you pass it. Two details decide most results: the interval argument belongs to the linear-model method (predict.lm) and is not in predict.glm, and for glm models the default output is on the link scale, not the response scale. This guide covers both, with the arguments exactly as the R manual lists them.

What predict() is used for in research

predict() returns predictions from the results of a model-fitting function. In research it answers three different questions, and each one needs a different argument:

  • Predicted values for new cases. Pass a data frame as newdata to score observations that were not in the fitted data.
  • Uncertainty around the average prediction. For lm, interval = "confidence" bounds the mean response at the given predictor values.
  • Uncertainty around one new observation. For lm, interval = "prediction" bounds a single new observation, so it is wider than the confidence interval. See confidence interval for the underlying idea.

Because predict is a generic function, the same call works on many model classes, but the arguments available differ by class. The sections below separate the lm, glm and time-series cases.

Install or access

predict() belongs to the stats package that ships with base R, so there is nothing extra to install. R itself is distributed from CRAN (cran.r-project.org). To see which arguments your model class accepts, open the help page for the method, for example ?predict.lm or ?predict.glm, or the generic’s page with ?predict.

Step-by-step: predict from a linear model

The steps use the cars data set that ships with R. The usage line below is abridged from the R manual for predict.lm: predict(object, newdata, se.fit = FALSE, scale = NULL, df = Inf, interval = c("none", "confidence", "prediction"), level, type, pred.var, ...).

  1. Fit the model.
    fit <- lm(dist ~ speed, data = cars)
  2. Build a data frame of new predictor values. The columns must carry the same names as the predictors in the model formula. The manual describes newdata as “an optional data frame in which to look for variables with which to predict.”
    new <- data.frame(speed = c(10, 15, 20))
  3. Get point predictions.
    predict(fit, newdata = new)

    This returns one predicted value per row of new.

  4. Add a confidence interval for the mean response.
    predict(fit, newdata = new, interval = "confidence", level = 0.95)
  5. Add a prediction interval for a single new observation.
    predict(fit, newdata = new, interval = "prediction", level = 0.95)
  6. Request standard errors when you need them.
    predict(fit, newdata = new, se.fit = TRUE)

Predicting from a glm: link scale versus response scale

For generalized linear models the usage line in the manual is predict(object, newdata = NULL, type = c("link", "response", "terms"), se.fit = FALSE, ...). The type argument sets the scale of the output:

  • type = "link" is the default and returns predictions on the scale of the linear predictor. For a logistic model that is the log-odds scale, not probabilities.
  • type = "response" returns predictions on the scale of the response. For a logistic model that is the predicted probability.
  • type = "terms" returns a matrix with the fitted value of each term in the model formula.
m <- glm(am ~ wt, data = mtcars, family = binomial)
predict(m, newdata = data.frame(wt = c(2.5, 3.5)))                    # link scale
predict(m, newdata = data.frame(wt = c(2.5, 3.5)), type = "response") # response scale

The glm method has no interval argument. With se.fit = TRUE it returns a list with the predictions, their standard errors and residual.scale (the square root of the dispersion used for the standard errors), so any interval has to be built from those. The full model-fitting workflow is in Logistic Regression in R.

Output and how to read it

The shape of what comes back depends on the arguments:

Call What is returned
predict(fit, newdata) on an lm A vector of predictions
predict(fit, newdata, interval = "confidence") or "prediction" A matrix of predictions and bounds with column names fit, lwr and upr
predict(fit, newdata, se.fit = TRUE) A list that includes the standard errors of the predicted means
predict(glm_fit, newdata, se.fit = TRUE) A list: fit, se.fit and residual.scale

Read fit as the predicted value and lwr and upr as the lower and upper bounds at the requested level. For the same newdata, the "prediction" bounds are wider than the "confidence" bounds because they cover one new observation rather than the mean. Use the confidence interval when the claim is about the average relationship, and the prediction interval when the claim is about where an individual outcome will fall. For interpreting the model itself, see Regression Analysis and Confidence Interval Explained.

Troubleshooting

Predictions come back for the original data, not my new rows

If newdata is omitted, the fitted values are used. Check that the argument is named newdata and that it is a data frame. The related accessor is covered in fitted() in R.

Factor columns and variable types

The manual for the predict generic says considerable attempts are made to match the columns in newdata to those used for fitting, for example that they are of comparable types and that any factors have the same level set in the same order, or can be transformed to be so. Build factor columns in newdata with the levels used in the fit.

Rank-deficient fits

The predict.lm manual states that prediction from a rank-deficient fit only makes sense if newdata is contained in the same subspace as the original data.

Weighted fits with newdata

For a weighted fit with newdata, the default in predict.lm is to assume constant prediction variance, with a warning. The pred.var and weights arguments override that default, so a prediction interval from a weighted model needs one of them set deliberately.

Polynomial and spline terms

The predict.lm page points to the SafePrediction note in the manual for models that use data-dependent basis terms such as polynomials and splines. Read it before predicting from those models.

Time series models

Per the generic’s manual, time series prediction methods in the stats package take an n.ahead argument rather than newdata.

Free alternatives

R is free, and so is the main Python equivalent for regression models. The table maps the same tasks between them.

Task R (stats) Python (statsmodels)
Predicted values for new data predict(fit, newdata = new) results.predict(exog) on a fitted regression result
Intervals for the mean and for new observations interval = "confidence" or "prediction" in predict.lm results.get_prediction(exog), which returns a prediction results object with tables for the mean and for new observations

For a tree-based model in R, the same predict() call applies, with arguments set by the model’s package; see Random Forests in R.

FAQ

What does predict() do in R?

It is a generic function that returns predictions from a fitted model. R dispatches to a method based on the class of the first argument, so predict(fit, ...) runs predict.lm for an lm object and predict.glm for a glm object.

What is the difference between a confidence interval and a prediction interval in predict()?

Both come from interval in predict.lm. "confidence" bounds the mean response at the given predictor values; "prediction" bounds a single new observation and is wider.

What does type = “response” do?

In predict.glm it returns predictions on the scale of the response instead of the default linear-predictor (link) scale. For a binomial model with a logit link that means probabilities rather than log-odds.

Why does predict() return fitted values instead of my new predictions?

When newdata is omitted, the fitted values are used. Supply a data frame as newdata to get predictions for new rows.

Can I get an interval from predict() on a glm?

The predict.glm usage has no interval argument. Use se.fit = TRUE to get standard errors and build the interval from them.

Sources

Follow CASRAI

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

Ask CASRAI · free to try

Ask about Predict in R: predict(), newdata and Intervals

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 →