GAM package Testing

Notes taken from https://en.wikibooks.org/wiki/R_Programming/Nonparametric_Methods.

N <- 10^3
u <- rnorm(N)
x1 <- rnorm(N)
x2 <- rnorm(N) + x1
y <- 1 + x1^2 + x2^3 + u
library(gam)
g1 <- gam(y ~ x1 + x2 ) # Standard linear model
par(mfrow=c(1,2))
plot(g1, se = T)

g1 <- gam(y ~ s(x1) + x2 ) # x1 is locally estimated
par(mfrow=c(1,2))
plot(g1, se = T)

g1 <- gam(y ~ s(x1) + s(x2) ) # x1 and x2 are locally estimated
par(mfrow=c(1,2))
plot(g1, se = T)

library(mgcv)
g1 <- gam(y ~ s(x1) + s(x2) ) # x1 and x2 are locally estimated
par(mfrow=c(1,2))
plot(g1, se = T)