# predict

##### Model Predictions

`predict`

is a generic function for predictions from the results of
various model fitting functions. The function invokes particular
*methods* which depend on the `class`

of
the first argument.

- Keywords
- methods

##### Usage

`predict (object, …)`

##### Arguments

- object
a model object for which prediction is desired.

- …
additional arguments affecting the predictions produced.

##### Details

Most prediction methods which are similar to those for linear models
have an argument `newdata`

specifying the first place to look for
explanatory variables to be used for prediction. Some considerable
attempts are made to match up 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).

Time series prediction methods in package stats have an argument
`n.ahead`

specifying how many time steps ahead to predict.

Many methods have a logical argument `se.fit`

saying if standard
errors are to returned.

##### Value

The form of the value returned by `predict`

depends on the
class of its argument. See the documentation of the
particular methods for details of what is produced by that method.

##### References

Chambers, J. M. and Hastie, T. J. (1992)
*Statistical Models in S*.
Wadsworth & Brooks/Cole.

##### See Also

`predict.glm`

,
`predict.lm`

,
`predict.loess`

,
`predict.nls`

,
`predict.poly`

,
`predict.princomp`

,
`predict.smooth.spline`

.

SafePrediction for prediction from (univariable) polynomial and spline fits.

For time-series prediction,
`predict.ar`

,
`predict.Arima`

,
`predict.arima0`

,
`predict.HoltWinters`

,
`predict.StructTS`

.

##### Examples

`library(stats)`

```
# NOT RUN {
require(utils)
## All the "predict" methods found
## NB most of the methods in the standard packages are hidden.
## Output will depend on what namespaces are (or have been) loaded.
## IGNORE_RDIFF_BEGIN
for(fn in methods("predict"))
try({
f <- eval(substitute(getAnywhere(fn)$objs[[1]], list(fn = fn)))
cat(fn, ":\n\t", deparse(args(f)), "\n")
}, silent = TRUE)
## IGNORE_RDIFF_END
# }
```

*Documentation reproduced from package stats, version 3.6.1, License: Part of R 3.6.1*

### Community examples

**lord.feynman@gmail.com**at Apr 13, 2017 stats v3.3.3

``` #creates the x-axis (size) and y-axis (price) size <- c(2104, 1416, 1534, 852) price <- c(460, 232, 315, 178) data1 <- data.frame(size, price) plot(size, price, col = 2, pch = 16, xlab = "Size in feet²", ylab = "Price ($) in 1000", main = "Size versus Price") #makes a linear regression of the data lm_prices <- lm(price ~ size, data = data1) #uses the lm_prices' coef to plot the best line abline(coef(lm_prices), lwd = 1) lines(size[order(size)], price[order(price)], col = "blue") #predic the price for 1200 feet² size_1200 <- data.frame(size = 1200) predict(lm_prices, size_1200) ```