CommencerCommencer gratuitement

Multivariate GAMs of auto performance

GAMs can accept multiple variables of different types. In the following exercises, you'll work with the mpg dataset available in the gamair package to practice fitting models of different forms.

Cet exercice fait partie du cours

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Afficher le cours

Instructions

  • Use the head() and str() functions to examine the mpg data set.
  • Fit a GAM to these data to predict city.mpg as the sum of smooth functions of weight, length, and price.
  • Use the plot() function provided to visualize the model.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

library(mgcv)

# Examine the data
___
___

# Fit the model
mod_city <- gam(city.mpg ~ ___, 
                data = mpg, method = "REML")

# Plot the model
plot(mod_city, pages = 1)
Modifier et exécuter le code