Load the GAM package
library(gam)
Create the data and visualize
mydata <- data.frame(x = seq(from = -1,
to = 1,
length.out = 200),
y = x^2 + 0.1*rnorm(n = length(x)))
plot(mydata$x, mydata$y)

Check the \(R^2\) value to assess fit
(Rsquared <- 1-(mygam$deviance/mygam$null.deviance))
[1] 0.9014021
LS0tCnRpdGxlOiAiU2ltcGxlIGV4YW1wbGUgb2YgdXNpbmcgR0FNIGZvciBub25saW5lYXIgYXNzb2NpYXRpb24gc3R1ZGllcyIKb3V0cHV0OiBodG1sX25vdGVib29rCi0tLQoKIyBMb2FkIHRoZSBHQU0gcGFja2FnZQoKYGBge3J9CmxpYnJhcnkoZ2FtKQpgYGAKCiMgQ3JlYXRlIHRoZSBkYXRhIGFuZCB2aXN1YWxpemUKCmBgYHtyfQpteWRhdGEgPC0gZGF0YS5mcmFtZSh4ID0gc2VxKGZyb20gPSAtMSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0byA9IDEsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuZ3RoLm91dCA9IDIwMCksCiAgICAgICAgICAgICAgICAgICAgIHkgPSB4XjIgKyAwLjEqcm5vcm0obiA9IGxlbmd0aCh4KSkpCnBsb3QobXlkYXRhJHgsIG15ZGF0YSR5KQpgYGAKCiMgUGVyZm9ybSB0aGUgR0FNIGZpdCBhbmQgcGxvdCByZXN1bHRzCgpgYGB7cn0KbXlnYW0gPC0gZ2FtKHkgfiBzKHgpLCBkYXRhID0gbXlkYXRhKQpzdW1tYXJ5KG15Z2FtKQpwbG90KG15Z2FtLCByZXNpZHVhbHMgPSBUUlVFKQpgYGAKCiMgQ2hlY2sgdGhlICRSXjIkIHZhbHVlIHRvIGFzc2VzcyBmaXQKCmBgYHtyfQooUnNxdWFyZWQgPC0gMS0obXlnYW0kZGV2aWFuY2UvbXlnYW0kbnVsbC5kZXZpYW5jZSkpCmBgYA==