library(mgcv)
## Loading required package: nlme
## This is mgcv 1.8-18. For overview type 'help("mgcv-package")'.
set.seed(2) ## simulate some data... 
dat <- gamSim(1,n=400, dist = "poisson", scale = 0.1)
## Gu & Wahba 4 term additive model
fit1 <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat, 
            family = poisson(), method = "ML")
summary(fit1)
## 
## Family: poisson 
## Link function: log 
## 
## Formula:
## y ~ s(x0) + s(x1) + s(x2) + s(x3)
## 
## Parametric coefficients:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)  0.75899    0.03511   21.62   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Approximate significance of smooth terms:
##         edf Ref.df Chi.sq  p-value    
## s(x0) 2.137   2.67  5.706   0.0857 .  
## s(x1) 1.000   1.00 33.832 6.01e-09 ***
## s(x2) 5.231   6.35 81.884 4.78e-15 ***
## s(x3) 1.000   1.00  3.255   0.0712 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## R-sq.(adj) =  0.228   Deviance explained = 21.2%
## -ML = 715.99  Scale est. = 1         n = 400
AIC(fit1)
## [1] 1428.794
fit1$aic
## [1] 1425.752
fit2 <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat, 
            family = poisson(), 
            method = "REML")
summary(fit2)
## 
## Family: poisson 
## Link function: log 
## 
## Formula:
## y ~ s(x0) + s(x1) + s(x2) + s(x3)
## 
## Parametric coefficients:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)  0.75761    0.03516   21.55   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Approximate significance of smooth terms:
##         edf Ref.df Chi.sq  p-value    
## s(x0) 2.559  3.190  7.027   0.0781 .  
## s(x1) 1.046  1.090 33.362 1.26e-08 ***
## s(x2) 5.388  6.516 82.517 4.95e-15 ***
## s(x3) 1.414  1.713  4.260   0.1448    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## R-sq.(adj) =  0.232   Deviance explained = 21.6%
## -REML = 724.38  Scale est. = 1         n = 400
AIC(fit2)
## [1] 1429.832
fit2$aic
## [1] 1425.625