ComenzarEmpieza gratis

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 ejercicio forma parte del curso

Feature Engineering in R

Ver curso

Instrucciones del ejercicio

  • Build a linear model for the newton data using the linear model from base R function and assign it to lr_force.
  • Create a new data frame df by binding the prediction values to the original newton data.
  • Generate a scatterplot of force versus distance using ggplot().
  • Add a regression line to the scatterplot with the fitted values.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# 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()
Editar y ejecutar código