A tentative model
You are handed a data set with measures of the gravitational force between two bodies at different distances and are challenged to build a simple model to predict such force given a specific distance. Initially, you want to stick to simple linear regression. The data consist of 120 pairs of distance and force, and is loaded for you as newton.
Este exercício faz parte do curso
Feature Engineering in R
Instruções do exercício
- Build a linear model for the
newtondata using the linear model from baseRfunction and assign it tolr_force. - Create a new data frame
dfby binding the prediction values to the originalnewtondata. - Generate a scatterplot of
forceversusdistanceusingggplot(). - Add a regression line to the scatterplot with the fitted values.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Build a linear model for the newton the data and assign it to lr_force
lr_force <- ___(force ~ distance, data = ___)
# Create a new data frame by binding the prediction values to the original data
df <- newton %>% ___(lr_pred = predict(lr_force))
# Generate a scatterplot of force vs. distance
df %>%
ggplot(aes(x = distance, y = force)) +
geom____() +
# Add a regression line with the fitted values
geom_line(aes(y = ___), color = "blue", lwd = .75) +
ggtitle("Linear regression of force vs. distance") +
theme_classic()