Aan de slagGa gratis aan de slag

Adding categorical to the auto performance model

Now you'll include categorical variables in your model. Categories are inherently linear, so you'll model them as linear terms.

Deze oefening maakt deel uit van de cursus

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Cursus bekijken

Oefeninstructies

  • Fit a GAM to the mpg data, modeling city.mpg as a sum of smooth functions of weight, length, and price, and also include the categorical terms fuel, drive, and style.
  • Use the plot() function provided to visualize the model.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

library(mgcv)

# Fit the model
mod_city2 <- gam(city.mpg ~ s(weight) + s(length) + s(price) ___, 
                 data = mpg, method = "REML")

# Plot the model
plot(mod_city2, all.terms = TRUE, pages = 1)
Code bewerken en uitvoeren