Perform the following steps to visualize the generalized additive model:
- Generate a scatter plot using the nox and dis variables:
> plot(nox, dis)
Scatter plot of variable nox against dis
- Add the regression to the scatter plot:
> x = seq(0, 1, length = 500) > y = predict(fit, data.frame(nox = x)) > lines(x, y, col = "red", lwd = 2)
Fitted regression of gam on a scatter plot
- Alternatively, you can plot the fitted model using the plot function:
> plot(fit)
Plot of fitted gam