Kom igångKom igång 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.

Den här övningen är en del av kursen

Feature Engineering in R

Visa kurs

Övningsinstruktioner

  • 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.

Interaktiv övning med praktiskt arbete

Testa den här övningen genom att slutföra den här exempelkoden.

# 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()
Redigera och kör kod