> library(bootstrap) > data(cholost) > x <- cholost[ , 1] > y <- cholost[ , 2] > > plot(x, y) > library(modreg) > out <- loess(y ~ x, + control = loess.control(surface = "direct")) > summary(out) Call: loess(formula = y ~ x, control = loess.control(surface = "direct")) Number of Observations: 164 Equivalent Number of Parameters: 4.05 Residual Standard Error: 21.47 Trace of smoother matrix: 4.4 Control settings: normalize: TRUE span : 0.75 degree : 2 family : gaussian surface : direct > curve(predict(out, newdata = data.frame(x = x)), + add = TRUE, col = "blue") > > out <- loess(y ~ x) > curve(predict(out, newdata = data.frame(x = x)), + add = TRUE, col = "green") > help(lowess) > > out <- lowess(x, y) > names(out) [1] "x" "y" > lines(out, col = "red") > library(mgcv) This is mgcv 0.8-9 > out <- gam(y ~ s(x, bs = "cr")) > summary(out) Family: gaussian Link function: identity Formula: y ~ s(x, bs = "cr") Parametric coefficients: Estimate std. err. t ratio Pr(>|t|) constant 26.69 1.782 14.97 < 2.22e-16 Approximate significance of smooth terms: edf chi.sq p-value s(x) 5.671 167.64 < 2.22e-16 R-sq.(adj) = 0.503 Deviance explained = 52% GCV score = 466.58 Scale est. = 447.6 n = 164 > curve(predict(out, newdata = data.frame(x = x)), + add = TRUE, col = "green") > library(sm) Library `sm', version 2; Copyright (C) 1997, 2000 A.W.Bowman & A.Azzalini type help(sm) for summary information > h <- hcv(x, y, grid = 16) > print(h) [1] 6.056031 > out <- sm.regression(x, y, h, display = "none") > lines(out$eval.points, out$estimate, col = "purple") > > library(KernSmooth) KernSmooth 2.22 installed Copyright M. P. Wand 1997 > h <- dpill(x, y) > out <- locpoly(x, y, bandwidth = h) > lines(out, col = "red") > > out <- smooth.spline(x, y) > print(out) Call: smooth.spline(x = x, y = y) Smoothing Parameter spar= 0.7161806 lambda= 0.001110886 (12 iterations) Equivalent Degrees of Freedom (Df): 7.70965 Penalized Criterion: 27843.06 GCV: 464.3896 > curve(predict(out, x = x)$y, add = TRUE, col = "orange") > > data(housing) > names(housing) [1] "Sat" "Infl" "Type" "Cont" "Freq" > sapply(housing, class) $Sat [1] "ordered" "factor" $Infl [1] "factor" $Type [1] "factor" $Cont [1] "factor" $Freq [1] "integer" > sapply(housing, ) > names(housing$Sat) NULL > sapply(housing, levels) $Sat [1] "Low" "Medium" "High" $Infl [1] "Low" "Medium" "High" $Type [1] "Tower" "Apartment" "Atrium" "Terrace" $Cont [1] "Low" "High" $Freq NULL > out <- glm(Freq ~ Infl * Type * Cont + Sat, data = housing, family = poisson) > addterm(out, ~ . + Sat : (Infl + Type + Cont), test = "Chisq") Single term additions Model: Freq ~ Infl * Type * Cont + Sat Df Deviance AIC LRT Pr(Chi) 217.46 610.43 Infl:Sat 4 111.08 512.05 106.37 < 2.2e-16 *** Type:Sat 6 156.79 561.76 60.67 3.292e-11 *** Cont:Sat 2 212.33 609.30 5.13 0.07708 . --- Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1