Aan de slagGa gratis aan de slag

Plotting the motorcycle crash model and data

For our first plotting exercise, we'll add partial residuals to the partial effect plot of a GAM so as to compare the model to the data.

Deze oefening maakt deel uit van de cursus

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Cursus bekijken

Oefeninstructies

  • Plot the model (mod) that uses mcycle data. Add partial residuals to the plot.
  • Make a second plot, making partial residuals more visible by changing the shape using the pch argument, and size of the residuals using the cex argument. Set both the pch and cex arguments to 1.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

library(mgcv)
# Fit the model
mod <- gam(accel ~ s(times), data = mcycle, method = "REML")

# Make the plot with residuals
plot(mod, ___)

# Change shape of residuals
___
Code bewerken en uitvoeren