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.
Latihan ini adalah bagian dari kursus
Nonlinear Modeling with Generalized Additive Models (GAMs) in R
Petunjuk latihan
- Plot the model (
mod) that usesmcycledata. Add partial residuals to the plot. - Make a second plot, making partial residuals more visible by changing the shape using the
pchargument, and size of the residuals using thecexargument. Set both thepchandcexarguments to 1.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
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
___