Code Studio: Fit and Predict a Model (modelr)
Follow Model Basics: fit a linear model to modelr's sim1 data, then use it to predict.
- Fit
y ~ xtosim1withlm(). - Print the intercept and slope, rounded to 3 decimal places, as
Intercept: …andSlope: …. - The program reads some x values on one line, separated by spaces. Put them in a tibble with a column
x, add predictions withadd_predictions(), and print each asx = … -> y = …with y rounded to 2 decimal places.
For the input 1 5 the last two lines are:
x = 1 -> y = 6.27 x = 5 -> y = 14.48
Try an x well outside the data, like 50. Should you trust that prediction?
Follow Model Basics: fit a linear model to modelr's sim1 data, then use it to predict.
- Fit
y ~ xtosim1withlm(). - Print the intercept and slope, rounded to 3 decimal places, as
Intercept: …andSlope: …. - The program reads some x values on one line, separated by spaces. Put them in a tibble with a column
x, add predictions withadd_predictions(), and print each asx = … -> y = …with y rounded to 2 decimal places.
For the input 1 5 the last two lines are:
x = 1 -> y = 6.27 x = 5 -> y = 14.48
Try an x well outside the data, like 50. Should you trust that prediction?