Commit 72c03ae4 authored by Dirk Eddelbuettel's avatar Dirk Eddelbuettel

Import Upstream version 1.7-9

parent ac677317
Package: mgcv
Version: 1.7-8
Version: 1.7-9
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-10-10 17:19:53 UTC; simon
Packaged: 2011-10-20 08:31:33 UTC; simon
Repository: CRAN
Date/Publication: 2011-10-10 17:51:59
Date/Publication: 2011-10-20 11:21:34
ed855c1a5ee811c55fe614288ddb85da *DESCRIPTION
b89ea3fff6d53982d22fed46c3ddc916 *DESCRIPTION
abc5e760b0f5dd22c81d7614c0b304f0 *NAMESPACE
4553efb64e4def029f7c5bdfc0168936 *R/bam.r
257095aabda92b283b68e1b4a55a7976 *R/gam.fit3.r
902657a0ee2dedc3fdfa501bf3b37c5b *R/gam.sim.r
085b8b34e68292c173a22e55aca86562 *R/gamm.r
143fbfcc4e84daea905504cdcb88382d *R/mgcv.r
027eb86db613780842ec085493fd7e79 *R/plots.r
bff0e42dd1b9de24f3834d4d08245252 *R/smooth.r
f20157d570c32d97592a2b8f697fc102 *R/mgcv.r
bbd7903e5e048077e53dfbffbb1d9526 *R/plots.r
5344c3e25715ebeca3996f2d6baba454 *R/smooth.r
fe9745f610246ee1f31eb915ca0d76a9 *R/sparse.r
d70df05baa5919d6971b26b226e88ae8 *changeLog
0bd4225bb7c2e456039476e43b10fba9 *changeLog
e468195a83fab90da8e760c2c3884bd3 *data/columb.polys.rda
40874e3ced720a596750f499ded8a60a *data/columb.rda
88d77139cc983317b6acd8c5f1252ab9 *gnugpl2.txt
......@@ -31,7 +31,7 @@ f764fb7cb9e63ff341a0075a3854ab5d *man/exclude.too.far.Rd
9ac808f5a2a43cf97f24798c0922c9bf *man/formXtViX.Rd
34308f4ada8e2aca9981a17794dac30b *man/formula.gam.Rd
6f405acde2d7b6f464cf45f5395113ba *man/full.score.Rd
6e4bbb08f94dbe91d808f8ad1335ff3b *man/gam.Rd
3869522b0596acf818c7a9a170c94d4e *man/gam.Rd
aeb7ec80d75244bc4f2f2fd796f86efd *man/gam.check.Rd
847599e287ecf79fbb7be2cb06d72742 *man/gam.control.Rd
fd98327327ba74bb1a61a6519f12e936 *man/gam.convergence.Rd
......@@ -59,7 +59,7 @@ aba56a0341ba9526a302e39d33aa9042 *man/interpret.gam.Rd
496388445d8cde9b8e0c3917cbe7461d *man/magic.post.proc.Rd
5c55658a478bd34d66daad46e324d7f4 *man/mgcv-FAQ.Rd
904b19ba280010d85d59a4b21b6d2f94 *man/mgcv-package.Rd
eaf9a06f1a4849970f1130263c826441 *man/mgcv.Rd
196ad09f09d6a5a44078e2282eb0a56f *man/mgcv.Rd
bb420a39f1f8155f0084eb9260fad89c *man/mgcv.control.Rd
18a9858b6f3ffde288b0bf9e1a5da2f6 *man/model.matrix.gam.Rd
3edd2618dcb4b366eeb405d77f3f633c *man/mono.con.Rd
......@@ -74,7 +74,7 @@ dffa2d51c704c610088fa02d7220b05e *man/notExp.Rd
8c0f8575b427f30316b639a326193aeb *man/pdTens.Rd
b388d29148264fd3cd636391fde87a83 *man/pen.edf.Rd
de454d1dc268bda008ff46639a89acec *man/place.knots.Rd
82f8427d8807e1ef1999798b8972a7ca *man/plot.gam.Rd
ced71ada93376fcdffa28ad08009cf49 *man/plot.gam.Rd
3d1484b6c3c2ea93efe41f6fc3801b8d *man/polys.plot.Rd
fdd6b7e03fde145e274699fe9ea8996c *man/predict.gam.Rd
a594eb641cae6ba0b83d094acf4a4f81 *man/print.gam.Rd
......@@ -89,11 +89,11 @@ f77ca1471881d2f93c74864d076c0a0e *man/rTweedie.Rd
10a456bc3d7151f60be24a7e3bba3d30 *man/smooth.construct.ad.smooth.spec.Rd
9f05449c0114748608f99693ec25cf3f *man/smooth.construct.cr.smooth.spec.Rd
995e79cf7a23027c60d113481083c1cd *man/smooth.construct.ds.smooth.spec.Rd
70738776c2f6f885e08aad9396b2f494 *man/smooth.construct.fs.smooth.spec.Rd
651d90947f23423ac6cf65176d318932 *man/smooth.construct.mrf.smooth.spec.Rd
1bb6748d4d2934e48f0572bc5114ffcb *man/smooth.construct.fs.smooth.spec.Rd
e0c041d7ec47290741e82fd71c408995 *man/smooth.construct.mrf.smooth.spec.Rd
78688702b6396f24692b74c554483428 *man/smooth.construct.ps.smooth.spec.Rd
0b134a171b9c5f8194787bf243f9c962 *man/smooth.construct.re.smooth.spec.Rd
9ff90a4670411d01d2cfaa0a2bd464cc *man/smooth.construct.sos.smooth.spec.Rd
53d7986dd7a54c1edb13ce84dbfe34a2 *man/smooth.construct.sos.smooth.spec.Rd
8672633a1fad8df3cb1f53d7fa883620 *man/smooth.construct.tensor.smooth.spec.Rd
a84c09609eedb6902b3ef7c8885010dd *man/smooth.construct.tp.smooth.spec.Rd
1de9c315702476fd405a85663bb32d1c *man/smooth.terms.Rd
......
......@@ -191,7 +191,9 @@ mgcv <- function(y,X,sp,S,off,C=NULL,w=rep(1,length(y)),H=NULL,scale=1,gcv=TRUE,
# edf - array of model edf's from final grid search for overall s.p.
# score - array of gcv/ubre scores corresponding to edf.
#
{ if (gcv) scale <- -1
{ .Deprecated("magic")
if (gcv) scale <- -1
if (!is.null(C)) C.r<-nrow(C) # number of equality constraints
else {C.r<-0;C<-0}
......@@ -3343,4 +3345,4 @@ set.mgcv.options <- function()
# * add randomized residuals (see Mark B email)?
#
# * sort out all the different scale parameters floating around, and explain the
# sp variance link better.
\ No newline at end of file
# sp variance link better.
This diff is collapsed.
......@@ -2209,7 +2209,7 @@ smooth.construct.sos.smooth.spec<-function(object,data,knots)
## Now get the rk matrix...
if (is.na(object$p.order)) object$p.order <- 1
if (is.na(object$p.order)) object$p.order <- 0
object$p.order <- round(object$p.order)
if (object$p.order< -1) object$p.order <- -1
if (object$p.order>4) object$p.order <- 4
......
** denotes quite substantial/important changes
*** denotes really big changes
1.7-9
* rather lovely plot method added for splines on the sphere.
* plot.gam modified to allow 'scheme' to be specified for plots, to easily
select different plot looks.
* schemes added for default smooth plotting method, modified for mrfs and
factor-smooth interactions.
* mgcv function deprected, since magic and gam are much better (let me know
if this is really a problem).
1.7-8
* gamm.setup fix. Bug introduced in 1.7-7 whereby gamm with no smooths would
......
......@@ -364,7 +364,7 @@ print(b)
## change the smoothness selection method to REML
b0<-gam(y~s(x0)+s(x1)+s(x2)+s(x3),data=dat,method="REML")
plot(b,pages=1)
plot(b,pages=1,scheme=1)
## ... and do automatic terms selection as well
b1<-gam(y~s(x0)+s(x1)+s(x2)+s(x3),data=dat,
......@@ -374,7 +374,7 @@ plot(b1,pages=1)
## set the smoothing parameter for the first term, estimate rest ...
bp<-gam(y~s(x0)+s(x1)+s(x2)+s(x3),sp=c(0.01,-1,-1,-1),data=dat)
plot(bp,pages=1)
plot(bp,pages=1,scheme=1)
## alternatively...
bp <- gam(y~s(x0,sp=.01)+s(x1)+s(x2)+s(x3),data=dat)
......@@ -432,7 +432,7 @@ b4<-gam(y~s(x0)+s(x1)+s(x2)+s(x3),family=poisson,
data=dat,method="GACV.Cp",scale=-1)
plot(b4,pages=1)
## repeat using REML as in Wood 2009...
## repeat using REML as in Wood 2011...
b5<-gam(y~s(x0)+s(x1)+s(x2)+s(x3),family=poisson,
data=dat,method="REML")
......@@ -472,7 +472,7 @@ Ey <- exp(dat$f);scale <- .5 ## mean and GLM scale parameter
dat$y <- rgamma(Ey*0,shape=1/scale,scale=Ey*scale)
bg <- gam(y~ s(x0)+ s(x1)+s(x2)+s(x3),family=Gamma(link=log),
data=dat,method="REML")
plot(bg,pages=1)
plot(bg,pages=1,scheme=1)
## For inverse Gaussian, see ?rig
......@@ -496,23 +496,28 @@ par(op)
## largish dataset example with user defined knots
##################################################
par(mfrow=c(1,1))
par(mfrow=c(2,2))
eg <- gamSim(2,n=10000,scale=.5)
attach(eg)
ind<-sample(1:10000,1000,replace=FALSE)
b5<-gam(y~s(x,z,k=50),data=data,
knots=list(x=data$x[ind],z=data$z[ind]))
vis.gam(b5)
## various visualizations
vis.gam(b5,theta=30,phi=30)
plot(b5)
plot(b5,scheme=1,theta=50,phi=20)
plot(b5,scheme=2)
par(mfrow=c(1,1))
## and a pure "knot based" spline of the same data
b6<-gam(y~s(x,z,k=100),data=data,knots=list(x= rep((1:10-0.5)/10,10),
z=rep((1:10-0.5)/10,rep(10,10))))
vis.gam(b6,color="heat")
vis.gam(b6,color="heat",theta=30,phi=30)
## varying the default large dataset behaviour via `xt'
b7 <- gam(y~s(x,z,k=50,xt=list(max.knots=1000,seed=2)),data=data)
vis.gam(b7)
vis.gam(b7,theta=30,phi=30)
detach(eg)
################################################################
......
......@@ -161,6 +161,7 @@ especially in contexts where the weights vary wildly. }
}
\examples{
\dontrun{
library(help="mgcv") # listing of all routines
set.seed(1);n<-400;sig2<-4
......@@ -175,7 +176,7 @@ y <- f + e
G<-gam(y~s(x0)+s(x1)+s(x2)+s(x3),fit=FALSE)
# fit using mgcv
mgfit<-mgcv(G$y,G$X,G$sp,G$S,G$off,C=G$C)
}
}
\keyword{models} \keyword{smooth} \keyword{regression}%-- one or more ..
......
......@@ -12,7 +12,7 @@
ylab=NULL,main=NULL,ylim=NULL,xlim=NULL,too.far=0.1,
all.terms=FALSE,shade=FALSE,shade.col="gray80",
shift=0,trans=I,seWithMean=FALSE,by.resids=FALSE,
scheme="grey",...)
scheme=0,...)
}
%- maybe also `usage' for other objects documented here.
\arguments{
......@@ -105,8 +105,7 @@ and this is also suggested by simulation.}
\item{by.resids}{Should partial residuals be plotted for terms with \code{by} variables?
Usually the answer is no, they would be meaningless.}
\item{scheme}{\code{"grey"} yields greyscale, and \code{"heat"} heatmap colors, for plot methods
that take any notice of this (e.g. \code{\link{mrf}} smooths).}
\item{scheme}{Integer or integer vector selecting a plotting scheme for each plot. See details.}
\item{...}{ other graphics parameters to pass on to plotting commands.}
......@@ -116,15 +115,20 @@ Usually the answer is no, they would be meaningless.}
handled by \code{\link{termplot}}.
For smooth terms \code{plot.gam} actually calls plot method functions depending on the
class of the smooth. Currently random effect and Markov random field smooths have special methods,
class of the smooth. Currently \code{\link{random.effects}}, Markov random fields (\code{\link{mrf}}),
\code{\link{Spherical.Spline}} and
\code{\link{factor.smooth.interaction}} terms have special methods (documented in their help files),
the rest use the defaults described below.
For plots of 1-d smooths, the x axis of each plot is labelled
with the covariate name, while the y axis is labelled \code{s(cov,edf) } where \code{cov}
is the covariate name, and \code{edf} the estimated (or user defined for regression splines)
degrees of freedom of the smooth. \code{scheme == 0} produces a smooth curve with dashed curves
indicating 2 standard error bounds. \code{scheme == 1} illustrates the error bounds using a shaded
region.
For plots of 1-d smooths, the x axis of each plot is labelled
with the covariate name, while the y axis is labelled \code{s(cov,edf) } where \code{cov}
is the covariate name, and \code{edf} the estimated (or user defined for regression splines) degrees of freedom of the smooth.
Contour plots are produced for 2-d smooths with the x-axes labelled with the first covariate
For \code{scheme==0}, contour plots are produced for 2-d smooths with the x-axes labelled with the first covariate
name and the y axis with the second covariate name. The main title of
the plot is something like \code{s(var1,var2,edf)}, indicating the
variables of which the term is a function, and the estimated degrees of
......@@ -135,6 +139,8 @@ by the s.e. Contour levels are chosen to try and ensure reasonable
separation of the contours of the different plots, but this is not
always easy to achieve. Note that these plots can not be modified to the same extent as the other plot.
For 2-d smooths \code{scheme==1} produces a perspective plot, while \code{scheme==2} produces a heatmap,
with overlaid contours.
Smooths of more than 2 variables are not plotted, but see \code{\link{vis.gam}}.
......@@ -146,6 +152,12 @@ although each smooth is shown centred, the confidence bands are obtained as if e
constrained to have average 0, (average taken over the covariate values), except for the smooth concerned. This seems to correspond more closely to how most users interpret componentwise intervals in practice, and also results in intervals with
close to nominal (frequentist) coverage probabilities by an extension of Nychka's (1988) results.
Sometimes you may want a small change to a default plot, and the arguments to \code{plot.gam} just won't let you do it.
In this case, the quickest option is sometimes to clone the \code{smooth.construct} and \code{Predict.matrix} methods for
the smooth concerned, modifying only the returned smoother class (e.g. to \code{foo.smooth}).
Then copy the plot method function for the original class (e.g. \code{mgcv:::plot.mgcv.smooth}), modify the source code to plot exactly as you want and rename the plot method function (e.g. \code{plot.foo.smooth}). You can then use the cloned
smooth in models (e.g. \code{s(x,bs="foo")}), and it will automatically plot using the modified plotting function.
}
\value{ The function simply generates plots.
......@@ -223,11 +235,18 @@ for (i in 1:3) {
}
par(op)
## example with 2-d plots...
b1<-gam(y~x0+s(x1,x2)+s(x3))
op<-par(mfrow=c(2,2))
## example with 2-d plots, and use of schemes...
b1 <- gam(y~x0+s(x1,x2)+s(x3))
op <- par(mfrow=c(2,2))
plot(b1,all.terms=TRUE)
par(op)
op <- par(mfrow=c(2,2))
plot(b1,all.terms=TRUE,scheme=1)
par(op)
op <- par(mfrow=c(2,2))
plot(b1,all.terms=TRUE,scheme=c(2,1))
par(op)
}
\keyword{models} \keyword{smooth} \keyword{regression} \keyword{hplot}%-- one or more ...
......
......@@ -56,6 +56,8 @@ Note one computational bottleneck: currently \code{\link{gamm}} (or \code{gamm4}
smooths, including the smooths at each level of the factor. This matrix can get large and computationally costly if there
are more than a few hundred levels of the factor. Even at one or two hundred levels, care should be taken to keep
down \code{k}.
The plot method for this class has two schemes. \code{scheme==0} is in colour, while \code{scheme==1} is black and white.
}
......
......@@ -78,7 +78,8 @@ geographic area. Otherwise a low rank approximation is obtained based on truncat
Wood (2006) Section 4.10.4.
Note that smooths of this class have a built in plot method, and that the utility function \code{\link{in.out}}
can be useful for working with discrete area data.
can be useful for working with discrete area data. The plot method has two schemes, \code{scheme==0} is colour,
\code{scheme==1} is grey scale.
}
......@@ -100,14 +101,14 @@ xt <- list(polys=columb.polys) ## neighbourhood structure info for MRF
par(mfrow=c(2,2))
## First a full rank MRF...
b <- gam(crime ~ s(district,bs="mrf",xt=xt),data=columb,method="REML")
plot(b)
plot(b,scheme=1)
## Compare to reduced rank version...
b <- gam(crime ~ s(district,bs="mrf",k=20,xt=xt),data=columb,method="REML")
plot(b)
plot(b,scheme=1)
## An important covariate added...
b <- gam(crime ~ s(district,bs="mrf",k=20,xt=xt)+s(income),
data=columb,method="REML")
plot(b,shade=TRUE,scheme="heat")
plot(b,scheme=c(0,1))
## plot fitted values by district
par(mfrow=c(1,1))
......
......@@ -8,8 +8,8 @@
\description{\code{\link{gam}} can use isotropic smooths on the sphere, via terms like
\code{s(la,lo,bs="sos",m=2,k=100)}. There must be exactly 2 arguments to such a smooth.
The first is taken to be latitude (in degrees) and the second longitude (in degrees).
\code{m} (default 1) is an integer in the range 0 to 4 determining the order of the penalty used.
For \code{m>0}, \code{(m+2)/2} is the penalty order, so \code{m=2} is the equivalent to the usual second
\code{m} (default 0) is an integer in the range -1 to 4 determining the order of the penalty used.
For \code{m>0}, \code{(m+2)/2} is the penalty order, with \code{m=2} equivalent to the usual second
derivative penalty. \code{m=0} signals to use the 2nd order spline on the sphere, computed by
Wendelberger's (1981) method. \code{m = -1} results in a \code{\link{Duchon.spline}} being
used (with m=2 and s=1/2), following an unpublished suggestion of Jean Duchon.
......@@ -45,8 +45,8 @@ out duplicate locations).}
\details{ For \code{m>0}, the smooths implemented here are based on the pseudosplines on the sphere of Wahba (1981)
(there is a correction of table 1 in 1982, but the correction has a misprint in the definition of A --- the A
given in the 1981 paper is correct). For \code{m=0} then a second order spline on the sphere is used which is the analogue of
a second order thin plate spline in 2D: the computation is based on Chapter 4 of Wendelberger, 1981.
given in the 1981 paper is correct). For \code{m=0} (default) then a second order spline on the sphere is used which is the
analogue of a second order thin plate spline in 2D: the computation is based on Chapter 4 of Wendelberger, 1981.
Optimal low rank approximations are obtained using exactly the approach given in Wood (2003). For \code{m = -1} a smooth of the
general type discussed in Duchon (1977) is used: the sphere is embedded in a 3D Euclidean space, but
smoothing employs a penalty based on second derivatives (so that locally as the smoothing parameter tends
......@@ -55,6 +55,17 @@ Duchon.
Note that the null space of the penalty is always the space of constant functions on the sphere, whatever the order of penalty.
This class has a plot method, with 3 schemes. \code{scheme==0} plots one hemisphere of the sphere, projected onto a circle.
The plotting sphere has the north pole at the top, and the 0 meridian running down the middle of the plot, and towards
the viewer. The smoothing sphere is rotated within the plotting sphere, by specifying the location of its pole in the
co-ordinates of the viewing sphere. \code{theta}, \code{phi} give the longitude and latitude of the smoothing sphere pole
within the plotting sphere (in plotting sphere co-ordinates). (You can visualize the smoothing sphere as a globe, free to
rotate within the fixed transparent plotting sphere.) The value of the smooth is shown by a heat map overlaid with a
contour plot. lat, lon gridlines are also plotted.
\code{scheme==1} is as \code{scheme==0}, but in black and white, without the image plot. \code{scheme>1} calls the default
plotting method with \code{scheme} decremented by 2.
}
\references{
......@@ -67,8 +78,8 @@ Wendelberger, J. (1981) PhD Thesis, University of Winsconsin.
Wood, S.N. (2003) Thin plate regression splines. J.R.Statist.Soc.B 65(1):95-114
}
\author{ Simon N. Wood \email{simon.wood@r-project.org},
with help from Grace Wahba (m=0 case) and Jean Duchon (m = -1, case).}
\author{ Simon Wood \email{simon.wood@r-project.org},
with help from Grace Wahba (m=0 case) and Jean Duchon (m = -1 case).}
\examples{
set.seed(0)
......@@ -98,8 +109,6 @@ zm <- matrix(fz,30,60)
require(mgcv)
dat <- data.frame(la = la *180/pi,lo = lo *180/pi,y=y)
method <- "GCV.Cp";m <- 3
## fit spline on sphere model...
bp <- gam(y~s(la,lo,bs="sos",k=60),data=dat)
......@@ -116,9 +125,11 @@ cor(fitted(b),ff)
pd <- data.frame(la=gr$la*180/pi,lo=gr$lo*180/pi)
fv <- matrix(predict(b,pd),30,60)
par(mfrow=c(2,1),mar=c(4,4,1,1))
par(mfrow=c(2,2),mar=c(4,4,1,1))
contour(lom,lam,t(zm))
contour(lom,lam,t(fv))
plot(bp,rug=FALSE)
plot(bp,scheme=1,theta=-30,phi=20,pch=19,cex=.5)
}
\keyword{models} \keyword{regression}%-- one or more ..
......
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