predict()
is a commonly used function in R for making predictions from fitted models. Here is an example of how to use predict()
with a linear regression model:
main.r250 chars10 lines
In this example, we first create a linear regression model model
using the lm()
function. We then create a new data frame new_data
with values for the predictor variable wt
and use predict()
to generate predictions for the response variable mpg
. The predictions are stored in the predictions
variable, and we can view them by printing the variable to the console.
Note that predict()
can be used with many types of models, not just linear regression. It is a useful tool for making predictions in a variety of machine learning and data analysis applications.
gistlibby LogSnag