![]() ![]() Linear_model <- lm (dist ~speed, data = df ) # Predicts the future values predict (linear_model, newdata = variable_speed ) Now that we have a model, we can apply predict(). The linear model has returned the speed of the cars as per our input data behavior. ![]() My_linear_model <- lm (dist ~speed, data = df ) # Prints the model resultsĮxecuting this code will calculate the linear model results: Call: Next, we will use predict() to determine future values using this data.įirst, we need to compute a linear model for this data frame: # Creates a linear model This will assign a data frame a collection of speed and distance ( dist) values: speed dist For the purpose of this example, we can import the built-in dataset in R - “Cars”. ![]() newdata: Input data to predict the values.object: The class inheriting from the linear model.The predict() function in R is used to predict the values based on the input data. To complete this tutorial, you will need: In this article, you will explore how to use the predict() function in R. All the modeling aspects in the R program will make use of the predict() function in their own way, but note that the functionality of the predict() function remains the same irrespective of the case. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |