Commit c7eaaa75 authored by Dirk Eddelbuettel's avatar Dirk Eddelbuettel

Import Upstream version 1.7-2

parent c7dd87ef
Package: mgcv
Version: 1.7-1
Version: 1.7-2
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: 2010-11-05 16:43:24 UTC; simon
Packaged: 2010-11-12 10:50:02 UTC; simon
Repository: CRAN
Date/Publication: 2010-11-08 07:31:31
Date/Publication: 2010-11-13 15:19:37
......@@ -16,7 +16,7 @@ export(anova.gam, bam, bam.update, concurvity, cSplineDes,
mono.con, mroot, negbin, new.name,
notExp,notExp2,notLog,notLog2,pcls,null.space.dimension,
pen.edf,pdIdnot,pdTens,
place.knots, plot.gam, print.anova.gam,
place.knots, plot.gam, polys.plot,print.anova.gam,
print.gam,print.summary.gam,predict.gam,
PredictMat,Predict.matrix,Predict.matrix2,
Predict.matrix.cr.smooth,
......
......@@ -253,12 +253,12 @@ poly2 <- function(x,col) {
xf <- x
xf[ind,1] <- base[1]
xf[ind,2] <- base[2]
polygon(xf,col=col,border=NA,fillOddEven=TRUE)
if (!is.na(col)) polygon(xf,col=col,border=NA,fillOddEven=TRUE)
polygon(x,border="black")
}
}
polys.plot <- function(pc,z,scheme="heat",lab="") {
polys.plot <- function(pc,z=NULL,scheme="heat",lab="",...) {
## pc is a list of polygons defining area boundaries
## pc[[i]] is the 2 col matrix of vertex co-ords for polygons defining
## boundary of area i
......@@ -281,45 +281,61 @@ polys.plot <- function(pc,z,scheme="heat",lab="") {
}
} ## end of axes range loop
xmin <- xlim[1]
xlim[1] <- xlim[1] - .1 * (xlim[2]-xlim[1]) ## allow space for scale
n.col <- 100
if (scheme=="heat") scheme <- heat.colors(n.col) else
scheme <- gray(0:n.col/n.col)
mar <- par("mar");
oldpar <- par(mar=c(2,mar[2],2,1))
zlim <- range(pretty(z))
## Now want a grey or color scale up the lhs of plot
## first scale the y range into the z range for plotting
if (is.null(z)) { ## no z value, no shading, no scale, just outlines...
plot(0,0,ylim=ylim,xlim=xlim,xaxt="n",yaxt="n",type="n",bty="n",ylab=lab,xlab="",...)
for (i in 1:length(pc)) {
poly2(pc[[i]],col=NA)
}
} else {
nz <- names(z)
npc <- names(pc)
if (!is.null(nz)&&!is.null(npc)) { ## may have to re-order z into pc order.
if (all.equal(sort(nz),sort(npc))!=TRUE) stop("names of z and pc must match")
z <- z[npc]
}
xmin <- xlim[1]
xlim[1] <- xlim[1] - .1 * (xlim[2]-xlim[1]) ## allow space for scale
n.col <- 100
if (scheme=="heat") scheme <- heat.colors(n.col) else
scheme <- gray(0:n.col/n.col)
zlim <- range(pretty(z))
for (i in 1:length(pc)) pc[[i]][,2] <- zlim[1] +
(zlim[2]-zlim[1])*(pc[[i]][,2]-ylim[1])/(ylim[2]-ylim[1])
## Now want a grey or color scale up the lhs of plot
## first scale the y range into the z range for plotting
for (i in 1:length(pc)) pc[[i]][,2] <- zlim[1] +
(zlim[2]-zlim[1])*(pc[[i]][,2]-ylim[1])/(ylim[2]-ylim[1])
ylim <- zlim
plot(0,0,ylim=ylim,xlim=xlim,type="n",xaxt="n",bty="n",xlab="",ylab=lab)
for (i in 1:length(pc)) {
coli <- round((z[i] - zlim[1])/(zlim[2]-zlim[1])*100)
poly2(pc[[i]],col=scheme[coli])
}
ylim <- zlim
plot(0,0,ylim=ylim,xlim=xlim,type="n",xaxt="n",bty="n",xlab="",ylab=lab)
for (i in 1:length(pc)) {
coli <- round((z[i] - zlim[1])/(zlim[2]-zlim[1])*100)
poly2(pc[[i]],col=scheme[coli])
}
## now plot the scale bar...
#ylim <- range(axTicks(2))
xmin <- min(c(axTicks(1),xlim[1]))
dx <- (xlim[2]-xlim[1])*.05
x0 <- xmin-2*dx
x1 <- xmin+dx
dy <- (ylim[2]-ylim[1])/n.col
poly <- matrix(c(x0,x0,x1,x1,ylim[1],ylim[1]+dy,ylim[1]+dy,ylim[1]),4,2)
for (i in 1:n.col) {
polygon(poly,col=scheme[i],border=NA)
poly[,2] <- poly[,2] + dy
## now plot the scale bar...
xmin <- min(c(axTicks(1),xlim[1]))
dx <- (xlim[2]-xlim[1])*.05
x0 <- xmin-2*dx
x1 <- xmin+dx
dy <- (ylim[2]-ylim[1])/n.col
poly <- matrix(c(x0,x0,x1,x1,ylim[1],ylim[1]+dy,ylim[1]+dy,ylim[1]),4,2)
for (i in 1:n.col) {
polygon(poly,col=scheme[i],border=NA)
poly[,2] <- poly[,2] + dy
}
poly <- matrix(c(x0,x0,x1,x1,ylim[1],ylim[2],ylim[2],ylim[1]),4,2)
polygon(poly,border="black")
}
poly <- matrix(c(x0,x0,x1,x1,ylim[1],ylim[2],ylim[2],ylim[1]),4,2)
polygon(poly,border="black")
par(oldpar)
}
......@@ -496,7 +512,7 @@ plot.mgcv.smooth <- function(x,P=NULL,data=NULL,label="",se1.mult=1,se2.mult=2,
if (is.null(ylim)) ylim <- range(ym)
if (is.null(xlim)) xlim <- range(xm)
return(list(X=X,x=xm,y=ym,scale=FALSE,se=TRUE,raw=raw,xlab=xlabel,ylab=ylabel,
main=main,se.mult=se2.mult,ylim=ylim,xlim=xlim))
main=main,se.mult=se2.mult,ylim=ylim,xlim=xlim,exclude=exclude))
} ## end of 2D basic plot data production
} else { ## produce plot
if (se) { ## produce CI's
......@@ -549,6 +565,7 @@ plot.mgcv.smooth <- function(x,P=NULL,data=NULL,label="",se1.mult=1,se2.mult=2,
} ## rug plot done
} else if (x$dim==2) {
P$fit[P$exclude] <- NA
if (pers) { ## perspective plot
persp(P$x,P$y,matrix(trans(P$fit+shift),n2,n2),xlab=P$xlab,ylab=P$ylab,
zlab=P$main,ylim=P$ylim,xlim=P$xlim,theta=theta,phi=phi,...)
......@@ -583,6 +600,7 @@ plot.mgcv.smooth <- function(x,P=NULL,data=NULL,label="",se1.mult=1,se2.mult=2,
points(P$raw,trans(P$p.resid+shift),...)
}
} else if (x$dim==2) {
P$fit[P$exclude] <- NA
if (!is.null(main)) P$title <- main
if (pers) {
persp(P$x,P$y,matrix(trans(P$fit+shift),n2,n2),xlab=P$xlab,ylab=P$ylab,
......
......@@ -2,6 +2,13 @@
*** denotes really big changes
ISSUES:
1.7-2
* `polys.plot' now exported, to facilitate plotting of results for
models involving mrf terms.
* bug fix in plot.gam --- too.far had stopped working in 1.7-0.
1.7-1
* post fitting constraint modification would fail if model matrix was
......
......@@ -4,7 +4,7 @@
%- Also NEED an `\alias' for EACH other topic documented here.
\title{Update a strictly additive bam model for new data.}
\description{ Guassian with identity link models fitted by \code{\link{bam}} can be efficiently updated as new data becomes available,
\description{ Gaussian with identity link models fitted by \code{\link{bam}} can be efficiently updated as new data becomes available,
by simply updateing the QR decomposition on which estimation is based, and re-optimizing the smoothing parameters, starting
from the previous estimates. This routine implements this.
}
......
......@@ -30,7 +30,7 @@ within a \code{gam} model formula, isotropic smooths of any number of predictors
\code{\link{s}} terms, while scale invariant smooths of any number of
predictors can be specified using \code{\link{te}} terms. \code{\link{smooth.terms}} provides an
overview of the built in smooth classes, and \code{\link{random.effects}} should be refered to for an overview
of random effects terms. Estimation is by
of random effects terms (see also \code{\link{mrf}} for Markov random fields). Estimation is by
penalized likelihood or quasi-likelihood maximization, with smoothness
selection by GCV, GACV, gAIC/UBRE or (RE)ML. See \code{\link{gam}}, \code{\link{gam.models}},
\code{\link{linear.functional.terms}} and \code{\link{gam.selection}} for some discussion of model specification and
......@@ -75,7 +75,7 @@ For a complete list of functions type \code{library(help=mgcv)}. See also \code{
\author{
Simon Wood <simon.wood@r-project.org>
with contributions and/or help from Kurt Hornik, Mike Lonergan, Henric Nilsson
with contributions and/or help from Thomas Kneib, Kurt Hornik, Mike Lonergan, Henric Nilsson
and Brian Ripley.
Maintainer: Simon Wood <simon.wood@r-project.org>
......
\name{polys.plot}
\alias{polys.plot}
\title{Plot geographic regions defined as polygons}
\usage{
polys.plot(pc,z=NULL,scheme="heat",lab="",...)
}
\arguments{
\item{pc}{A named list of matrices. Each matrix has two columns. The matrix rows each define the
vertex of a boundary polygon. If a boundary is defined by several polygons, then each of these must be
separated by an \code{NA} row in the matrix. See \code{\link{mrf}} for an example.}
\item{z}{A vector of values associated with each area (item) of \code{pc}. If the vector elements
have names then these are used to match elements of \code{z} to areas defined in \code{pc}. Otherwise
\code{pc} and \code{z} are assumed to be in the same order. If \code{z} is \code{NULL} then polygons are not filled. }
\item{scheme}{One of \code{"heat"} or \code{"grey"}, indicating how to fill the polygons in accordance with the value
of \code{z}.}
\item{lab}{label for plot.}
\item{...}{other arguments to pass to plot (currently only if \code{z} is \code{NULL}).}
}
\value{Simply produces a plot.}
\description{ Produces plots of geographic regions defined by polygons, optionally filling the
polygons with a color or grey shade dependent on a covariate.
}
\details{Any polygon within another polygon counts as a hole in the area. Further nesting is dealt with by
treating any point that is interior to an odd number of polygons as being within the area, and all other points
as being exterior. The routine is provided to facilitate plotting with models containing \code{\link{mrf}} smooths.
}
\author{Simon Wood \email{simon.wood@r-project.org}
}
\seealso{
\code{\link{mrf}} and \code{\link{columb.polys}}.
}
\examples{
## see also ?mrf for use of z
data(columb.polys)
polys.plot(columb.polys)
}
\keyword{hplot} \keyword{models} \keyword{smooth} \keyword{regression}
......@@ -89,7 +89,7 @@ Wood S.N. (2006) Generalized additive models: an intriduction with R CRC.
\author{ Simon N. Wood \email{simon.wood@r-project.org} and Thomas Kneib
(Fabian Scheipl prorotyped the low rank MRF idea) }
\seealso{\code{\link{gam.vcomp}}, \code{\link{gamm}}, \code{\link{in.out}}}
\seealso{\code{\link{in.out}}, code{\link{polys.plot}}}
\examples{
library(mgcv)
......@@ -109,6 +109,12 @@ b <- gam(crime ~ s(district,bs="mrf",k=20,xt=xt)+s(income),
data=columb,method="REML")
plot(b,shade=TRUE,scheme="heat")
## plot fitted values by district
par(mfrow=c(1,1))
fv <- fitted(b)
names(fv) <- as.character(columb$district)
polys.plot(columb.polys,fv)
}
\keyword{models} \keyword{regression}%-- one or more ..
......
......@@ -111,10 +111,11 @@ smooth term is zero. Be warned, these are only approximate.}
\item{r.sq}{The adjusted r-squared for the model. Defined as the proportion of variance explained, where original variance and
residual variance are both estimated using unbiased estimators. This quantity can be negative if your model is worse than a one
parameter constant model, and can be higher for the smaller of two nested models! Note that proportion null deviance
explained is probably more appropriate for non-normal errors.}
parameter constant model, and can be higher for the smaller of two nested models! The proportion null deviance
explained is probably more appropriate for non-normal errors. Note that \code{r.sq} does not include any offset in the one parameter model.}
\item{dev.expl}{The proportion of the null deviance explained by the model.}
\item{dev.expl}{The proportion of the null deviance explained by the model. The null deviance is computed taking acount of any offset, so
\code{dev.expl} can be substantially lower than \code{r.sq} when an offset is present.}
\item{edf}{array of estimated degrees of freedom for the model terms.}
......
......@@ -6,8 +6,8 @@
in a \code{\link{gam}} formula. Results in a construction in which the penalties are
non-overlapping multiples of identity matrices (with some rows and columns zeroed).
The construction is analogous to Chong Gu's (2002) Smoothing Spline ANOVA, but using
low rank penalized regression spline marginals.
low rank penalized regression spline marginals. The main advantage of this construction
is that it is useable with \code{gamm4} from package \code{gamm4}.
}
\usage{t2(..., k=NA,bs="cr",m=NA,d=NA,by=NA,
......@@ -79,7 +79,8 @@ achieved by an arbitrary rescaling of null space basis vectors.}
used to represent smooths of one (or sometimes more) of the covariates. To do this `marginal' bases
are produced with associated model matrices and penalty matrices. These are reparameterized so that the
penalty is zero everywhere, except for some elements on the leading diagonal, which all have the same non-zero value.
This reparameterization results in an unpenalized and a penalized subset of parameters, for each marginal basis.
This reparameterization results in an unpenalized and a penalized subset of parameters, for each marginal basis (see
e.g. appendix of Wood, 2004, for details).
The re-parameterized marginal bases are then combined to produce a basis for a single function of all the covariates
(dimension given by the product of the dimensions of the marginal bases). In this set up there are multiple
......@@ -87,11 +88,13 @@ penalty matrices --- all zero, but for a mixture of a constant and zeros on the
a non-zero entry in the same place.
Essentially the basis for the tensor product can be thought of as being constructed from a set of
products of the penalized (range) or unpenalized (null) space bases of the marginal smooths. To construct one of the set, choose either the
products of the penalized (range) or unpenalized (null) space bases of the marginal smooths (see Gu, 2002, section 2.4).
To construct one of the set, choose either the
null space or the range space from each marginal, and from these bases construct a product basis. The result is subject to a ridge
penalty (unless it happens to be a product entirely of marginal null spaces). The whole basis for the smooth is constructed from
all the different product bases that can be constructed in this way. The separately penalized components of the smooth basis each
have an interpretation in terms of the ANOVA - decomposition of the term. See \code{\link{pen.edf}} for some further information.
have an interpretation in terms of the ANOVA - decomposition of the term.
See \code{\link{pen.edf}} for some further information.
Note that there are two ways to construct the product. When \code{full=FALSE} then the null space bases are treated as a whole in each product,
but when \code{full=TRUE} each null space column is treated as a separate null space. The latter results in more penalties, but is the strict
......@@ -146,15 +149,25 @@ values (defualt).}
}
\author{ Simon N. Wood \email{simon.wood@r-project.org}}
\author{ Simon N. Wood \email{simon.wood@r-project.org} and Fabian Scheipl}
\references{
Wood, S.N. (2006a) Low rank scale invariant tensor product smooths for
generalized additive mixed models. Biometrics 62(4):1025-1036
Gu, C. (2002) Smoothing Spline ANOVA, Springer.
Wood, S.N. (2004) Stable and efficient multiple smoothing parameter estimation for
generalized additive models. J. Amer. Statist. Ass. 99:673-686.
\url{http://people.bath.ac.uk/sw283/}
Alternative approaches to functional ANOVA decompositions,
*not* implemented by t2 terms, are discussed in:
Belitz and Lang (2008) Simultaneous selection of variables and smoothing parameters in structured additive regression models. Computational Statistics & Data Analysis, 53(1):61-81
Lee, D-J and M. Durban (2011) P-spline ANOVA type interaction models for spatio-temporal smoothing. Statistical Modelling
Wood, S.N. (2006) Low-Rank Scale-Invariant Tensor Product Smooths for Generalized Additive Mixed Models. Biometrics 62(4): 1025-1036.
}
\seealso{\code{\link{te}} \code{\link{s}},\code{\link{gam}},\code{\link{gamm}},
......
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