Get startedGet started for free

Plotting multiple auto performance variables

In plotting GAMs, you sometimes want to look at just parts of a model, or all the terms in model. Here you'll practice selecting which terms to visualize.

This exercise is part of the course

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

View Course

Exercise instructions

  • Plot the provided model (mod) that uses the mpg data, using the select term to view only the partial effect of price.
  • Make another plot, this time showing all terms on a single page, including the linear comp.ratio term.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

library(mgcv)
# Fit the model
mod <- gam(hw.mpg ~ s(weight) + s(rpm) + s(price) + comp.ratio, 
           data = mpg, method = "REML")

# Plot the price effect
___

# Plot all effects
___
Edit and Run Code