> library(MASS) > > data(GAGurine) > library(mgcv) This is mgcv 0.8-9 > out <- gam(GAG ~ s(Age, bs = "cr"), data = GAGurine) > attach(GAGurine) > plot(Age, log(GAG)) > curve(predict(out, newdata = data.frame(x = x)), + > curve(predict(out.log, newdata = data.frame(Age = x)), add = TRUE) Error in predict(out.log, newdata = data.frame(Age = x)) : Object "out.log" not found > out.log <- gam(log(GAG) ~ s(Age, bs = "cr"), data = GAGurine) > plot(Age, log(GAG)) > curve(predict(out.log, newdata = data.frame(Age = x)), add = TRUE) > lines(loess.smooth(Age, log(GAG)), col = "red") Warning message: k-d tree limited by memory. ncmax= 314 > library(KernSmooth) KernSmooth 2.22 installed Copyright M. P. Wand 1997 > lines(ksmooth(Age, log(GAG)), col = "green") > lines(ksmooth(Age, log(GAG), bandwidth = 5), col = "green") > > plot(Age, log(GAG)) > curve(predict(out.log, newdata = data.frame(Age = x)), add = TRUE) > library(sm) Error in library(sm) : There is no package called 'sm' > # see http://www.stat.umn.edu/geyer/old02/5601/examp/regtoo.html#kernel > h <- dpill(Age, log(GAG)) > h [1] 0.5760882 > plot(Age, log(GAG)) > curve(predict(out.log, newdata = data.frame(Age = x)), add = TRUE) > lines(locpoly(Age, log(GAG), degree = 1, bandwidth = h), col = "red") > x <- seq(0, (6 * pi)^2, length = 101) > y.true <- sin(sqrt(x)) > plot(x, y.true, type = "l") > > y <- y.true + rnorm(length(y)) * 0.15 > > plot(x, y) > y <- y.true + rnorm(length(y)) * 0.25 > plot(x, y) > out <- gam(y ~ s(x, bs = "cr")) > curve(predict(out, newdata = data.frame(x = x)), add = TRUE) > lines(supsmu(x, y), col = "red") > lines(x, y.true, col = "green") > data(rock) > names(rock) [1] "area" "peri" "shape" "perm" > out <- gam(log(perm) ~ s(area, bs = "cr") + s(peri, bs = "cr") + s(shape, bs = "cr")) Error in log(perm) : Object "perm" not found > attach(rock) > out <- gam(log(perm) ~ s(area, bs = "cr") + s(peri, bs = "cr") + s(shape, bs = "cr")) > summary(out) Family: gaussian Link function: identity Formula: log(perm) ~ s(area, bs = "cr") + s(peri, bs = "cr") + s(shape, bs = "cr") Parametric coefficients: Estimate std. err. t ratio Pr(>|t|) constant 5.0476 0.1245 40.53 < 2.22e-16 Approximate significance of smooth terms: edf chi.sq p-value s(area) 1 29.077 6.9576e-08 s(peri) 1 71.23 < 2.22e-16 s(shape) 1.409 1.614 0.30332 R-sq.(adj) = 0.735 Deviance explained = 75.4% GCV score = 0.78853 Scale est. = 0.7161 n = 48 > gam.check(out) Smoothing parameter selection converged after 10 iterations. The mean absolute GCV score gradient at convergence was 8.348908e-07 . The Hessian of the GCV score at convergence was positive definite. Note: the default second smoothing parameter guess failed. > plot(out) Press return for next page.... Press return for next page.... >