Commit b404fe09 authored by Dirk Eddelbuettel's avatar Dirk Eddelbuettel

Import Upstream version 1.7-6

parent 3ad22b97
Package: mgcv
Version: 1.7-5
Version: 1.7-6
Author: Simon Wood <simon.wood@r-project.org>
Maintainer: Simon Wood <simon.wood@r-project.org>
Title: GAMs with GCV/AIC/REML smoothness estimation and GAMMs by PQL
......@@ -12,6 +12,6 @@ Imports: graphics, stats, nlme, Matrix
Suggests: nlme (>= 3.1-64), splines, Matrix
LazyLoad: yes
License: GPL (>= 2)
Packaged: 2011-03-25 18:12:14 UTC; simon
Packaged: 2011-04-14 11:16:32 UTC; simon
Repository: CRAN
Date/Publication: 2011-03-26 15:44:25
Date/Publication: 2011-04-14 17:01:29
......@@ -343,8 +343,9 @@ bam.fit <- function(G,mf,chunk.size,gp,scale,gamma,method,rho=0)
X <- rwMatrix(stop,row,weight,sqrt(G$w)*G$X)
y <- rwMatrix(stop,row,weight,sqrt(G$w)*G$y)
qrx <- qr.update(X,y)
rm(X);gc() ## X can be large: remove and reclaim
}
rm(X);gc() ## X can be large: remove and reclaim
}
rss.extra <- qrx$y.norm2 - sum(qrx$f^2)
......@@ -568,7 +569,8 @@ bam <- function(formula,family=gaussian(),data=list(),weights=NULL,subset=NULL,n
object$residuals <- sqrt(family$dev.resids(object$y,object$fitted.values,object$weights)) *
sign(object$y-object$fitted.values)
object$deviance <- sum(object$residuals^2)
object$aic <- family$aic(object$y,1,object$fitted.values,object$weights,object$deviance)
object$aic <- family$aic(object$y,1,object$fitted.values,object$weights,object$deviance) +
2*sum(object$edf)
object$null.deviance <- sum(family$dev.resids(object$y,mean(object$y),object$weights))
class(object) <- c("gam","glm","lm")
object
......@@ -713,7 +715,7 @@ bam.update <- function(b,data,chunk.size=10000) {
b$residuals <- sqrt(b$family$dev.resids(b$y,b$fitted.values,b$weights)) *
sign(b$y-b$fitted.values)
b$deviance <- sum(b$residuals^2)
b$aic <- b$family$aic(b$y,1,b$fitted.values,b$weights,b$deviance)
b$aic <- b$family$aic(b$y,1,b$fitted.values,b$weights,b$deviance) + 2 * sum(b$edf)
b$null.deviance <- sum(b$family$dev.resids(b$y,mean(b$y),b$weights))
names(b$coefficients) <- names(b$edf) <- cnames
b
......
......@@ -2598,6 +2598,10 @@ smoothCon <- function(object,data,knots,absorb.cons=FALSE,scale.penalty=TRUE,n=n
if (matrixArg) stop("factor `by' variables can not be used with matrix arguments.")
sml <- list()
lev <- levels(by)
## if by variable is an ordered factor then first level is taken as a
## reference level, and smooths are only generated for the other levels
## this can help to ensure identifiability in complex models.
if (is.ordered(by)&&length(lev)>1) lev <- lev[-1]
for (j in 1:length(lev)) {
sml[[j]] <- sm ## replicate smooth for each factor level
by.dum <- as.numeric(lev[j]==by)
......
......@@ -2,6 +2,16 @@
*** denotes really big changes
ISSUES:
1.7-6
** factor `by' variable handling extended: if a by variable is an
ordered factor then the first level is treated as a reference level
and smooths are only generated for the other levels. This is useful
for avoiding identifiability issues in complex models with factor by
variables.
* bam bug fix. aic was reported incorrectly (too low).
1.7-5
* gam.fit3 modified to converge more reliably with links that don't guarantee
......
......@@ -111,13 +111,19 @@ functionals of smooths.
The \code{\link{s}} and \code{\link{te}} terms used to specify smooths accept an argument \code{by},
which is a numeric or factor variable of the same dimension as the covariates of the smooth.
If a \code{by} variable is numeric, then its \eqn{i^{th}}{ith} element multiples the \eqn{i^{th}}{ith}
row of the model matrix corresponding to the smooth term concerned. If a \code{by} variable is a factor then it generates
an indicator vector for each level of the factor. The model matrix for the smooth term is then replicated for each factor level,
row of the model matrix corresponding to the smooth term concerned.
If a \code{by} variable is a \code{\link{factor}} then it generates an indicator vector for each level
of the factor, unless it is an \code{\link{ordered}} factor.
In the non-ordered case, the model matrix for the smooth term is then replicated for each factor level,
and each copy has its rows multiplied by the corresponding rows of its
indicator variable. The smoothness penalties are also duplicated for each
factor level. In short a different smooth is generated
for each factor level (the \code{id} argument to \code{\link{s}} and \code{\link{te}} can be used to force all
such smooths to have the same smoothing parameter).
such smooths to have the same smoothing parameter). \code{\link{ordered}} \code{by} variables are handled in the same
way, except that no smooth is generated for the first level of the ordered factor (see \code{b3} example below).
This is useful for setting up
identifiable models when the same smooth occurs more than once in a model, with different factor \code{by} variables.
As an example, consider the model
......@@ -270,6 +276,14 @@ b2 <- gam(y ~ fac+s(x2,by=fac,id=1)+s(x0),data=dat)
plot(b2,pages=1)
summary(b2)
## now repeat with a single reference level smooth, and
## two `difference' smooths...
dat$fac <- ordered(dat$fac)
b3 <- gam(y ~ fac+s(x2)+s(x2,by=fac)+s(x0),data=dat,method="REML")
plot(b3,pages=1)
summary(b3)
rm(dat)
## An example of a simple random effects term implemented via
......
......@@ -13,7 +13,7 @@ gam.vcomp(x,rescale=TRUE,conf.lev=.95)
\item{x}{ a fitted model object of class \code{gam} as produced by \code{gam()}.}
\item{rescale}{ the penalty matrices for smooths are rescaled before fitting, for numerical
stability reasons, if \code{resale} this rescaling is reversed, so that the variance components
stability reasons, if \code{TRUE} this rescaling is reversed, so that the variance components
are on the original scale.}
\item{conf.lev}{ when the smoothing parameters are estimated by REML or ML, then confidence intervals
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment