Commit b33cf22f authored by Dirk Eddelbuettel's avatar Dirk Eddelbuettel

Import Upstream version 1.7-22

parent e252c2ab
Package: mgcv
Version: 1.7-21
Version: 1.7-22
Author: Simon Wood <simon.wood@r-project.org>
Maintainer: Simon Wood <simon.wood@r-project.org>
Title: Mixed GAM Computation Vehicle with GCV/AIC/REML smoothness
......@@ -14,6 +14,6 @@ Suggests: nlme (>= 3.1-64), splines, Matrix, parallel
LazyLoad: yes
ByteCompile: yes
License: GPL (>= 2)
Packaged: 2012-09-18 14:17:12 UTC; sw283
Packaged: 2012-10-14 19:28:35 UTC; sw283
Repository: CRAN
Date/Publication: 2012-09-18 14:45:44
Date/Publication: 2012-10-15 11:19:58
d164cab90e6024a6942dba6de5352cae *DESCRIPTION
f18b9a3e2aae6b0e649d8590a0eb17f1 *DESCRIPTION
3e152f2a5b0efaa9f28a3a976ed087e4 *NAMESPACE
7b5db03a3a80878eb8007f8c0848583a *R/bam.r
e59ee1842b4546cb64ebe39e6a7f00ee *R/fast-REML.r
2073e50d30aacc57abac1db8b3133467 *R/gam.fit3.r
902657a0ee2dedc3fdfa501bf3b37c5b *R/gam.sim.r
3527e64fa9d32baba5644c69c7d1eaf6 *R/gamm.r
7abad0459a93e7e451e018d0109612a8 *R/mgcv.r
adf0eadd4f8b76ac0a0feb6dfaabc7f5 *R/mgcv.r
8b4c61012d19bfd07321cc17fc4f9927 *R/plots.r
7223c8dcb8d3778f061848dd020558cc *R/smooth.r
034e8f9ace2bd40a1fb860c49419e677 *R/smooth.r
484800e6369585d11f6c7aef7631d9b0 *R/soap.r
fb66d6c18398411a99ffcb788b854f13 *R/sparse.r
a7e1bf5114a392453948022894bbed0e *changeLog
21f750feb19056a490a9afb39aac1622 *changeLog
e468195a83fab90da8e760c2c3884bd3 *data/columb.polys.rda
40874e3ced720a596750f499ded8a60a *data/columb.rda
88d77139cc983317b6acd8c5f1252ab9 *gnugpl2.txt
......@@ -23,12 +23,12 @@ e9b0a2e31b130cf2cb38618ec50d1919 *man/Predict.matrix.soap.film.Rd
0d24940b2e0a3e9fa7b3dc0224d049ab *man/anova.gam.Rd
585d6b6a2e7816df83d5f9193195a233 *man/bam.Rd
b385d6d5419d0d6aefe03af1a79d5c4e *man/bam.update.Rd
4e925cb579f4693d1b8ec2d5092c0b37 *man/cSplineDes.Rd
bb5ec26743d46d7ce1dbf128bceab35a *man/cSplineDes.Rd
9b4d616d1b6c4a46ca77d16cded3f806 *man/choose.k.Rd
c03748964ef606621418e428ae49b103 *man/columb.Rd
4196ba59f1fa8449c9cd0cab8a347978 *man/concurvity.Rd
f764fb7cb9e63ff341a0075a3854ab5d *man/exclude.too.far.Rd
702afc89845d640c9359253e394bcadc *man/extract.lme.cov.Rd
ee14c3984a1d6ad58abd16c9a611df3a *man/extract.lme.cov.Rd
44ad0563add1c560027d502ce41483f5 *man/fix.family.link.Rd
4d4eea9ad2b78e765a96b2a0065725c1 *man/fixDependence.Rd
9ac808f5a2a43cf97f24798c0922c9bf *man/formXtViX.Rd
......@@ -38,19 +38,19 @@ bb099e6320a6c1bd79fe4bf59e0fde08 *man/formula.gam.Rd
d7781fc09ad742a63746ea92a927eee4 *man/gam.Rd
fe61dd0efab9e920c17335faf3d5764c *man/gam.check.Rd
96c9417e4ac5d79ec9ed3f363adfc4e9 *man/gam.control.Rd
fd98327327ba74bb1a61a6519f12e936 *man/gam.convergence.Rd
44db24b66ce63bc16d2c8bc3f5b42ac5 *man/gam.convergence.Rd
58ab3b3d6f4fd0d008d73c3c4e6d3305 *man/gam.fit.Rd
21339a5d1eb8c83679dd9022ab682b5e *man/gam.fit3.Rd
8c4805c4afe742aa81ba96ee21a854a2 *man/gam.models.Rd
714e72ecfeda30b49bfc6c20690076d0 *man/gam.models.Rd
e969287d1a5c281faa7eb6cfce31a7c5 *man/gam.outer.Rd
96676186808802344a99f9d3170bf775 *man/gam.selection.Rd
76651917bd61fc6bc447bbb40b887236 *man/gam.side.Rd
78588cf8ed0af8eca70bba3bbed64dbe *man/gam.vcomp.Rd
3b4d858771c3c0a8a33ff426e194db76 *man/gam.side.Rd
b2ff252537dd2155524b774b2435e66e *man/gam.vcomp.Rd
a66a814cc4c6f806e824751fda519ae0 *man/gam2objective.Rd
807a8e175d84ba3eac87f8ef2931f6e4 *man/gamObject.Rd
0ac5fb78c9db628ce554a8f68588058c *man/gamSim.Rd
9c301060b3c35bc6ab83e6f38ce8d3b6 *man/gamm.Rd
1f5d723f2fa931297940e1a4a840d792 *man/get.var.Rd
39ae109127110152e97dc9f79e08bb14 *man/get.var.Rd
a2ea1233d43fac89e0cacbc09a8d31e2 *man/in.out.Rd
9c461959be1272edcb98ee7e20fdc317 *man/inSide.Rd
2f222eeeb3d7bc42f93869bf8c2af58a *man/influence.gam.Rd
......@@ -64,54 +64,54 @@ aba56a0341ba9526a302e39d33aa9042 *man/interpret.gam.Rd
496388445d8cde9b8e0c3917cbe7461d *man/magic.post.proc.Rd
9427464e63d70da15fc468961ef0c29b *man/mgcv-FAQ.Rd
42cc4e7dcfa64979db73c672980ac9b1 *man/mgcv-package.Rd
18a9858b6f3ffde288b0bf9e1a5da2f6 *man/model.matrix.gam.Rd
00ccf213c31910cd14f1df65a300eb33 *man/model.matrix.gam.Rd
bc9b89db7e7ff246749551c16f5f1f07 *man/mono.con.Rd
3a4090ac778273861d97077681a55df2 *man/mroot.Rd
0fec75a585ffc9524e36367f194ce23c *man/mroot.Rd
f0363e3309cca00db840ad0fb8359c0f *man/negbin.Rd
41de8762baab4fc0cf1224df168520fe *man/new.name.Rd
dffa2d51c704c610088fa02d7220b05e *man/notExp.Rd
150d7f8a427117353c5c2e466ff0bfae *man/notExp2.Rd
95b3e6686e9557b3278e21e350704ce9 *man/null.space.dimension.Rd
19939543d691f128e84d86fb5423541e *man/pcls.Rd
8b766a6ad848b0f1ca469e381ded0169 *man/new.name.Rd
7d8f62e182f7c428cc9d46ddd4d97d43 *man/notExp.Rd
445571cf0b115bf19a2d3474e70f59e7 *man/notExp2.Rd
9532f2ce26e3e6040c34db75976a0462 *man/null.space.dimension.Rd
2f0baa6f36924e60391c5e35b2261db9 *man/pcls.Rd
717d796acbaab64216564daf898b6d04 *man/pdIdnot.Rd
8c0f8575b427f30316b639a326193aeb *man/pdTens.Rd
b388d29148264fd3cd636391fde87a83 *man/pen.edf.Rd
de454d1dc268bda008ff46639a89acec *man/place.knots.Rd
1721f1b266d9e14827e8226e2cb74a81 *man/pen.edf.Rd
edf57071572275a8443b2f0b66d44424 *man/place.knots.Rd
84d54e8081b82cb8d96a33de03741843 *man/plot.gam.Rd
3d1484b6c3c2ea93efe41f6fc3801b8d *man/polys.plot.Rd
c27a6b886929b1dc83bf4b90cae848f9 *man/polys.plot.Rd
afca36f5b1a5d06a7fcab2eaaa029e7e *man/predict.bam.Rd
df63d7045f83a1dc4874fcac18a2303c *man/predict.gam.Rd
a594eb641cae6ba0b83d094acf4a4f81 *man/print.gam.Rd
b8ac3ed8fc05bb14c605b996404853cd *man/qq.gam.Rd
f77ca1471881d2f93c74864d076c0a0e *man/rTweedie.Rd
354798b41bf766baaa4d0bad85274c25 *man/random.effects.Rd
58b5c7bee1277e2362b029317d2f7e24 *man/random.effects.Rd
37669f97e17507f3ae2d6d1d74feb9d7 *man/residuals.gam.Rd
472cc8de5077f5511fe7eb2ad454767e *man/rig.Rd
f6f1333be2587ffef5970905b13468ea *man/rig.Rd
7258dfc0149fff020054117fd2ee6bd8 *man/s.Rd
690dddb35fd5986a6eeb39dd79fa33f9 *man/slanczos.Rd
3026df475af053acd2b742af875f626c *man/smooth.construct.Rd
747f1bdf9251d6cf95653aec67b02599 *man/smooth.construct.ad.smooth.spec.Rd
c07b9d5733913e8397a91bd2526f0d23 *man/smooth.construct.cr.smooth.spec.Rd
131c3f2131138ba5d6f6bcde4be5ac31 *man/smooth.construct.ds.smooth.spec.Rd
d07f7e4c812e8b798a969beb40dca8e2 *man/slanczos.Rd
b5a06918956fd10f23285b453c05bdb4 *man/smooth.construct.Rd
58198db8810ffe0f285d7393de893860 *man/smooth.construct.ad.smooth.spec.Rd
76013feaf70d00976bba0154b6f2c946 *man/smooth.construct.cr.smooth.spec.Rd
e571d0064d328b2c1698c4d06c2eba06 *man/smooth.construct.ds.smooth.spec.Rd
1bb6748d4d2934e48f0572bc5114ffcb *man/smooth.construct.fs.smooth.spec.Rd
772e6c18d25cfaf3d9c194031ee042fe *man/smooth.construct.mrf.smooth.spec.Rd
65f84caf46cc1abbfa8ef8d9f3b7bbe2 *man/smooth.construct.ps.smooth.spec.Rd
abe15377f471a2d8957a59c19eeef0bb *man/smooth.construct.ps.smooth.spec.Rd
d202c6718fb1138fdd99e6102250aedf *man/smooth.construct.re.smooth.spec.Rd
87931bec091f3f0570b60d0dea7f10e0 *man/smooth.construct.so.smooth.spec.Rd
53d7986dd7a54c1edb13ce84dbfe34a2 *man/smooth.construct.sos.smooth.spec.Rd
b67bb662654b968a583301789ecaaf62 *man/smooth.construct.so.smooth.spec.Rd
ce311e544603f1089562747652abce20 *man/smooth.construct.sos.smooth.spec.Rd
8672633a1fad8df3cb1f53d7fa883620 *man/smooth.construct.tensor.smooth.spec.Rd
76ca359e3eda6e32398da0d6cdf9903b *man/smooth.construct.tp.smooth.spec.Rd
aad11653a5d7c05ea4d3ad96dda42273 *man/smooth.terms.Rd
f0a8dc771f043b027fade5d40aec4792 *man/smooth.terms.Rd
0d12daea17e0b7aef8ab89b5f801adf1 *man/smoothCon.Rd
5ae47a140393009e3dba7557af175170 *man/sp.vcov.Rd
b55a396da77559dac553613146633f97 *man/sp.vcov.Rd
83bd8e097711bf5bd0fff09822743d43 *man/spasm.construct.Rd
700699103b50f40d17d3824e35522c85 *man/step.gam.Rd
b8a08ccd4c9371ff2735b5aefd3058b2 *man/summary.gam.Rd
6fbcf448bc473a870fde0025db272c7a *man/t2.Rd
04076444b2c99e9287c080298f9dc1d7 *man/te.Rd
c3c23641875a293593fe4ef032b44aae *man/tensor.prod.model.matrix.Rd
fbd45cbb1931bdb5c0de044e22fdd028 *man/uniquecombs.Rd
6e4e84b961c3ade48e23acebacd39c70 *man/vcov.gam.Rd
84a714ed8ef26e46e51947abe959762c *man/t2.Rd
27205a151fe03ce66941d2a53ff82f0f *man/te.Rd
6eebb6ef90374ee09453d6da6449ed79 *man/tensor.prod.model.matrix.Rd
06ca54aeca7231f01ce06187a1f6cae8 *man/uniquecombs.Rd
5b05216eaeea867397ab130bb1332164 *man/vcov.gam.Rd
0e045fc94ea00c17e703ae07923f549b *man/vis.gam.Rd
becbe3e1f1588f7292a74a97ef07a9ae *po/R-de.po
0bdfcf98961b0d52b60f806dc1dba77e *po/R-en@quot.po
......@@ -128,7 +128,7 @@ cd54024d76a9b53dc17ef26323fc053f *src/Makevars
49af97195accb65adc75620183d39a4c *src/general.h
227ab8e09ea73b4c3a68069d8e2dca74 *src/init.c
1635205c9d5bb9a5713663775f47fd2a *src/magic.c
066af9db587e5fe6e5cc4ff8c09ae9c2 *src/mat.c
14a2d29c6be01b083cbd9b5fff15025f *src/mat.c
de0ae24ea5cb533640a3ab57e0383595 *src/matrix.c
0f8448f67d16668f9027084a2d9a1b52 *src/matrix.h
6a9f57b44d2aab43aa32b01ccb26bd6e *src/mgcv.c
......@@ -138,5 +138,5 @@ fcbe85d667f8c7818d17509a0c3c5935 *src/misc.c
cd563899be5b09897d1bf36a7889caa0 *src/qp.h
3236a7cbc7030edbd6f1ebc3563c9faa *src/soap.c
e9cab4a461eb8e086a0e4834cbf16f30 *src/sparse-smooth.c
985ef1e19c7b5d97b8e29ed78e709fc5 *src/tprs.c
3a9712b746b358a0636b49088d79e582 *src/tprs.c
5352d5d2298acd9b03ee1895933d4fb4 *src/tprs.h
......@@ -2627,7 +2627,7 @@ recov <- function(b,re=rep(0,0),m=0) {
## to be moved to the end...
LRB <- cbind(LRB[,-ii],LRB[,ii])
ii <- (ncol(LRB)-length(ii)+1):ncol(LRB) ## need to pick up final block
Rm <- qr.R(qr(LRB,tol=0,LAPACK=FALSE))[ii,ii] ## unpivoted QR
Rm <- qr.R(qr(LRB,tol=0,LAPACK=FALSE))[ii,ii,drop=FALSE] ## unpivoted QR
} else Rm <- NULL
list(Ve= crossprod(L%*%b$R%*%b$Vp)/b$sig2, ## Frequentist cov matrix
......@@ -2648,7 +2648,7 @@ reTest <- function(b,m) {
rc <- recov(b,rind,m)
Ve <- rc$Ve
ind <- b$smooth[[m]]$first.para:b$smooth[[m]]$last.para
B <- mroot(Ve[ind,ind]) ## BB'=Ve
B <- mroot(Ve[ind,ind,drop=FALSE]) ## BB'=Ve
Rm <- rc$Rm
......@@ -2683,7 +2683,7 @@ testStat <- function(p,X,V,rank=NULL,type=0,res.df= -1) {
qrx <- qr(X,tol=0)
R <- qr.R(qrx)
V <- R%*%V[qrx$pivot,qrx$pivot]%*%t(R)
V <- R%*%V[qrx$pivot,qrx$pivot,drop=FALSE]%*%t(R)
V <- (V + t(V))/2
ed <- eigen(V,symmetric=TRUE)
......@@ -2727,7 +2727,7 @@ testStat <- function(p,X,V,rank=NULL,type=0,res.df= -1) {
if (b12<0) b12 <- 0
b12 <- sqrt(b12)
B <- matrix(c(1,b12,b12,nu),2,2)
ev <- diag(ed$values[k:k1]^-.5)
ev <- diag(ed$values[k:k1]^-.5,nrow=k1-k+1)
B <- ev%*%B%*%ev
eb <- eigen(B,symmetric=TRUE)
rB <- eb$vectors%*%diag(sqrt(eb$values))%*%t(eb$vectors)
......
......@@ -1521,14 +1521,33 @@ smooth.construct.ps.smooth.spec<-function(object,data,knots)
class(object)<-"pspline.smooth" # Give object a class
object
}
} ### end of p-spline constructor
Predict.matrix.pspline.smooth<-function(object,data)
# prediction method function for the p.spline smooth class
{ require(splines)
X <- spline.des(object$knots,data[[object$term]],object$m[1]+2)$design
m <- object$m[1]+1
## find spline basis inner knot range...
ll <- object$knots[m+1];ul <- object$knots[length(object$knots)-m]
m <- m + 1
x <- data[[object$term]]
n <- length(x)
ind <- x<=ul & x>=ll ## data in range
if (sum(ind)==n) { ## all in range
X <- spline.des(object$knots,x,m)$design
} else { ## some extrapolation needed
## matrix mapping coefs to value and slope at end points...
D <- spline.des(object$knots,c(ll,ll,ul,ul),m,c(0,1,0,1))$design
X <- matrix(0,n,ncol(D)) ## full predict matrix
X[ind,] <- spline.des(object$knots,x[ind],m)$design ## interior rows
## Now add rows for linear extrapolation...
ind <- x < ll
if (sum(ind)>0) X[ind,] <- cbind(1,x[ind]-ll)%*%D[1:2,]
ind <- x > ul
if (sum(ind)>0) X[ind,] <- cbind(1,x[ind]-ul)%*%D[3:4,]
}
X
}
......
......@@ -3,12 +3,24 @@
ISSUES:
* users can use as.factor(a) in formula, and variable.summary won't know
about it - causes a problem is a is character, for example. Could coerce
character to factor, but is that general enough? what about if a was numeric
then summary doesn't reflect how it's used?
* F needed in gam object?
* still not really happy with nesting constraints, especially under rank
deficiency.
1.7-22
* Predict.matrix.pspline.smooth now allows prediction outside range of knots,
and uses linear extrapolation in this case.
* missing drop=FALSE in reTest called by summary.gam caused 1-D random effect
p-value computation to fail. Fixed (thanks Silje Skår).
1.7-21
** soap film smoother class added. See ?soap
......
......@@ -31,6 +31,7 @@ last knot locations.}
\seealso{\code{\link{cyclic.p.spline}}}
\examples{
require(mgcv)
## create some x's and knots...
n <- 200
x <- 0:(n-1)/(n-1);k<- 0:5/5
......
......@@ -87,6 +87,7 @@ and Hall/CRC Press.
}
\examples{
require(mgcv)
library(nlme)
data(Rail)
b <- lme(travel~1,Rail,~1|Rail)
......
......@@ -30,7 +30,7 @@ the smoothing basis to use \code{bs="cr"} (see \code{\link{s}} for details)
for 1-d smooths, and to use \code{\link{te}} smooths in place of
\code{\link{s}} smooths for smooths of more than one variable. This is because
the default thin plate regression spline basis \code{"tp"} is costly to set up
for large datasets (much over 1000 data, say).
for large datasets (much over 1000 data, say). (iv) consider using \code{\link{bam}}.
If the GAM estimation process fails to converge when using performance
iteration, then switch to outer iteration via the \code{optimizer} argument of
......
......@@ -250,6 +250,7 @@ and Hall/CRC Press.
\author{ Simon N. Wood \email{simon.wood@r-project.org}}
\examples{
require(mgcv)
set.seed(10)
## simulate date from y = f(x2)*x1 + error
dat <- gamSim(3,n=400)
......
......@@ -56,6 +56,7 @@ prediction matrices for the term.
\examples{
set.seed(7)
require(mgcv)
dat <- gamSim(n=400,scale=2) ## simulate data
## estimate model with redundant smooth interaction...
b<-gam(y~s(x0)+s(x1)+s(x0,x1)+s(x2),data=dat)
......
......@@ -63,7 +63,7 @@ models. Journal of the Royal Statistical Society (B) 73(1):3-36
\examples{
set.seed(3)
require(mgcv)
## simulate some data, consisting of a smooth truth + random effects
dat <- gamSim(1,n=400,dist="normal",scale=2)
......
......@@ -29,6 +29,7 @@ function returns \code{NULL}.}
\seealso{ \code{\link{gam} } }
\examples{
require(mgcv)
y <- 1:4;dat<-data.frame(x=5:10)
get.var("x",dat)
get.var("y",dat)
......
......@@ -34,6 +34,7 @@ and Hall/CRC Press.
\examples{
require(mgcv)
n <- 15
x <- runif(n)
y <- sin(x*2*pi) + rnorm(n)*.2
......
......@@ -31,6 +31,7 @@ problems into ordinary regression problems.}
\author{ Simon N. Wood \email{simon.wood@r-project.org}}
\examples{
require(mgcv)
set.seed(0)
a <- matrix(runif(24),6,4)
A <- a\%*\%t(a) ## A is +ve semi-definite, rank 4
......
......@@ -28,6 +28,7 @@ so that there is no clash.}
\seealso{ \code{\link{gamm} } }
\examples{
require(mgcv)
old <- c("a","tuba","is","tubby")
new.name("tubby",old)
}
......
......@@ -48,6 +48,7 @@ notLog(x)
\examples{
## Illustrate the notExp function:
## less steep than exp, but still monotonic.
require(mgcv)
x <- -100:100/10
op <- par(mfrow=c(2,2))
plot(x,notExp(x),type="l")
......
......@@ -68,6 +68,7 @@ notLog2(x,d=.Options$mgcv.vc.logrange,b=1/d)
\examples{
## Illustrate the notExp2 function:
require(mgcv)
x <- seq(-50,50,length=1000)
op <- par(mfrow=c(2,2))
plot(x,notExp2(x),type="l")
......
......@@ -51,6 +51,7 @@ Wood, S.N. (2003) Thin plate regression splines. J.R.Statist.Soc.B 65(1):95-114
\seealso{\code{\link{tprs}}}
\examples{
require(mgcv)
null.space.dimension(2,0)
}
\keyword{models} \keyword{regression}%-- one or more ..
......
......@@ -88,6 +88,7 @@ Journal on Scientific Computing 15(5):1126-1133
\seealso{ \code{\link{magic}}, \code{\link{mono.con}} }
\examples{
require(mgcv)
# first an un-penalized example - fit E(y)=a+bx subject to a>0
set.seed(0)
n<-100
......
......@@ -31,6 +31,7 @@ actually needed in a model.
\examples{
require(mgcv)
set.seed(20)
dat <- gamSim(1,n=400,scale=2) ## simulate data
## following `t2' smooth basically separates smooth
......
......@@ -29,6 +29,7 @@ even coverage, where even means having approximately the same number of data bet
\seealso{ \code{\link{smooth.construct.cc.smooth.spec}} }
\examples{
require(mgcv)
x<-runif(30)
place.knots(x,7)
rm(x)
......
......@@ -45,6 +45,7 @@ as being exterior. The routine is provided to facilitate plotting with models co
}
\examples{
## see also ?mrf for use of z
require(mgcv)
data(columb.polys)
polys.plot(columb.polys)
}
......
......@@ -49,7 +49,7 @@ generalized additive mixed models. Biometrics 62(4):1025-1036
## see also examples for gam.models, gam.vcomp and gamm
## simple comparison of lme and gam
require(mgcv)
require(nlme)
b0 <- lme(travel~1,data=Rail,~1|Rail,method="REML")
......
......@@ -45,13 +45,13 @@ with multiple roots. The American Statistician 30, 88-90.
\examples{
require(mgcv)
set.seed(7)
## An inverse.gaussian GAM example, by modify `gamSim' output...
dat <- gamSim(1,n=400,dist="normal",scale=1)
dat$f <- dat$f/4 ## true linear predictor
Ey <- exp(dat$f);scale <- .5 ## mean and GLM scale parameter
## Note that `shape' and `scale' in `rgamma' are almost
## opposite terminology to that used with GLM/GAM...
## simulate inverse Gaussian response...
dat$y <- rig(Ey,mean=Ey,scale=.2)
big <- gam(y~ s(x0)+ s(x1)+s(x2)+s(x3),family=inverse.gaussian(link=log),
data=dat,method="REML")
......
......@@ -54,6 +54,7 @@ Demmel, J. (1997) Applied Numerical Linear Algebra. SIAM
\seealso{\code{\link{cyclic.p.spline}}}
\examples{
require(mgcv)
## create some x's and knots...
set.seed(1);
n <- 700;A <- matrix(runif(n*n),n,n);A <- A+t(A)
......
......@@ -206,7 +206,7 @@ constraint free parameterizations.}
## Adding a penalized truncated power basis class and methods
## as favoured by Ruppert, Wand and Carroll (2003)
## Semiparametric regression CUP. (No advantage to actually
## using this, since mgcv can happliy handle non-identity
## using this, since mgcv can happily handle non-identity
## penalties.)
smooth.construct.tr.smooth.spec<-function(object,data,knots)
......@@ -260,9 +260,8 @@ Predict.matrix.tr.smooth<-function(object,data)
X # return the prediction matrix
}
# an example, using the new class....
require(mgcv)
set.seed(100)
dat <- gamSim(1,n=400,scale=2)
b<-gam(y~s(x0,bs="tr",m=2)+s(x1,bs="ps",m=c(1,3))+
......
......@@ -66,6 +66,7 @@ This class can not be used as a marginal basis in a tensor product smooth, nor b
\examples{
## Comparison using an example taken from AdaptFit
## library(AdaptFit)
require(mgcv)
set.seed(0)
x <- 1:1000/1000
mu <- exp(-400*(x-.6)^2)+5*exp(-500*(x-.75)^2)/3+2*exp(-500*(x-.9)^2)
......
......@@ -84,6 +84,7 @@ and Hall/CRC Press.
\examples{
## cyclic spline example...
require(mgcv)
set.seed(6)
x <- sort(runif(200)*10)
z <- runif(200)
......
......@@ -95,6 +95,7 @@ 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}}
\examples{
require(mgcv)
eg <- gamSim(2,n=200,scale=.05)
attach(eg)
op <- par(mfrow=c(2,2),mar=c(4,4,1,1))
......
......@@ -44,13 +44,16 @@ with a third order difference penalty (0th order is a ridge penalty) on the coef
The default basis dimension, \code{k}, is the larger of 10 and \code{m[1]+1} for a \code{"ps"} terms and the larger of 10 and \code{m[1]} for a \code{"cp"} term. \code{m[1]+1} and \code{m[1]} are the lower limits on basis dimension for the two types.
If knots are supplied, then the number of knots should be one more than the basis dimension
(i.e. \code{k+1}) for a \code{"cp"}smooth. For the \code{"ps"} basis the number of supplied knots should be \code{k + m[1] + 2}, and the range of the middle
\code{k-m[1]} knots should include all the covariate values. See example.
(i.e. \code{k+1}) for a \code{"cp"}smooth. For the \code{"ps"} basis the number of supplied knots should be \code{k + m[1] + 2}, and the range of the middle \code{k-m[1]} knots should include all the covariate values. See example.
Alternatively, for both types of smooth, 2 knots can be supplied, denoting the
lower and upper limits between which the spline can be evaluated (Don't make this range too wide, however, or you
can end up with no information about some basis coefficients, because the corresponding basis functions have a
span that includes no data!). Note that P-splines don't make much sense with uneven knot spacing.
Linear extrapolation is used for prediction that requires extrapolation
(i.e. prediction outside the range of the interior \code{k-m[1]} knots). Such extrapolation is not
allowed in basis construction, but is when predicting.
}
\references{
......@@ -65,6 +68,7 @@ Statistical Science, 11(2):89-121
\examples{
## see ?gam
## cyclic example ...
require(mgcv)
set.seed(6)
x <- sort(runif(200)*10)
z <- runif(200)
......
......@@ -140,6 +140,7 @@ boundary and the interior knots, plus the boundary smooth basis dimension(s)). I
\seealso{\code{\link{Predict.matrix.soap.film}}}
\examples{
require(mgcv)
##########################
......
......@@ -82,6 +82,7 @@ Wood, S.N. (2003) Thin plate regression splines. J.R.Statist.Soc.B 65(1):95-114
with help from Grace Wahba (m=0 case) and Jean Duchon (m = -1 case).}
\examples{
require(mgcv)
set.seed(0)
n <- 400
......
......@@ -2,13 +2,13 @@
\alias{smooth.terms}
\title{Smooth terms in GAM}
\description{
Smooth terms are specified in a \code{\link{gam}} formula using \code{\link{s}} and \code{\link{te}} terms.
Smooth terms are specified in a \code{\link{gam}} formula using \code{\link{s}}, \code{\link{te}} and \code{\link{t2}} terms.
Various smooth classes are available, for different modelling tasks, and users can add smooth classes
(see \code{\link{user.defined.smooth}}). What defines a smooth class is the basis used to represent
the smooth function and quadratic penalty (or multiple penalties) used to penalize
the basis coefficients in order to control the degree of smoothness. Smooth classes are
invoked directly by \code{s} terms, or as building blocks for tensor product smoothing
via \code{te} terms (only smooth classes with single penalties can be used in tensor products). The smooths
via \code{te} or \code{t2} terms (only smooth classes with single penalties can be used in tensor products). The smooths
built into the \code{mgcv} package are all based one way or another on low rank versions of splines. For the full rank
versions see Wahba (1990).
......@@ -25,8 +25,8 @@ smooth for \code{s} terms because there is a defined sense in which they are the
basis dimension/rank (Wood, 2003). Thin plate regression splines do not have `knots'
(at least not in any conventional sense): a truncated eigen-decomposition is used to achieve the rank reduction. See \code{\link{tprs}} for further details.
\code{bs="ts"} is as \code{"tp"} but with a small ridge penalty added to the smoothing penalty, so that the whole term can be
shrunk to zero.}
\code{bs="ts"} is as \code{"tp"} but with a modification to the smoothing penalty, so that the null space is also penalized slightly and the
whole term can therefore be shrunk to zero.}
\item{Duchon splines}{\code{bs="ds"}. These generalize thin plate splines. In particular, for any given number of covariates they
allow lower orders of derivative in the penalty than thin plate splines (and hence a smaller null space).
......@@ -57,8 +57,7 @@ on the basis coefficients, and any sane combination of penalty and basis order i
\item{Random effects}{\code{bs="re"}. These are parametric terms penalized by a ridge penalty (i.e. the identity matrix). When such a smooth has multiple arguments
then it represents the parametric interaction of these arguments, with the coefficients penalized by a ridge penalty. The ridge penalty is equivalent to an
assumption that the coefficients are i.i.d. normal random effects. See \code{\link{smooth.construct.re.smooth.spec}}. Note that random effect terms are not suitable
for use in tensor product smooths.}
assumption that the coefficients are i.i.d. normal random effects. See \code{\link{smooth.construct.re.smooth.spec}}.}
\item{Markov Random Fields}{\code{bs="mrf"}. These are popular when space is split up into discrete contiguous
geographic units (districts of a town, for example). In this case a simple smoothing penalty is constructed
......@@ -69,7 +68,7 @@ based on the neighbourhood structure of the geographic units. See \code{\link{mr
}
Broadly speaking the default penalized thin plate regression splines tend to give the best MSE performance,
but they are a little slower to set up than the other bases. The knot based penalized cubic regression splines
but they are slower to set up than the other bases. The knot based penalized cubic regression splines
(with derivative based penalties) usually come next in MSE performance, with the P-splines doing
just a little worse. However the P-splines are useful in non-standard situations.
......@@ -87,17 +86,17 @@ distance, an isotropic smoother will give very different results if the units ar
Some further specialist smoothers that are not suitable for use in tensor products are also available.
\describe{
\item{Adaptive smoothers}{\code{bs="ad"}}
\item{Adaptive smoothers}{\code{bs="ad"}
Univariate and bivariate adaptive smooths are available (see \code{\link{adaptive.smooth}}).
These are appropriate when the degree of smoothing should itself vary with the covariates to be smoothed, and the
data contain sufficient information to be able to estimate the appropriate variation. Because this flexibility is
achieved by splitting the penalty into several `basis penalties' these terms are not suitable as components of tensor
product smooths, and are not supported by \code{gamm}.
product smooths, and are not supported by \code{gamm}.}
\item{Factor smooth interactions}{\code{bs="fs"}}
\item{Factor smooth interactions}{\code{bs="fs"}
Smooth factor interactions are often produced using \code{by} variables (see \code{\link{gam.models}}), but a special smoother
class (see \code{\link{factor.smooth.interaction}}) is available for the case in which a smooth is required at each of a large number of factor levels (for example a smooth for each patient in a study), and each smooth should have the same smoothing parameter. The \code{"fs"} smoothers are set up to be efficient when used with \code{\link{gamm}}, and have penalties on each null sapce component (i.e. they are fully `random effects').
}
}
}
......
......@@ -35,6 +35,7 @@ Wood, S.N. (2006) On confidence intervals for generalized additive models based
\examples{
require(mgcv)
n <- 100
x <- runif(n);z <- runif(n)
y <- sin(x*2*pi) + rnorm(n)*.2
......
......@@ -182,6 +182,7 @@ Wood, S.N. (2006) Low-Rank Scale-Invariant Tensor Product Smooths for Generalize
# following shows how tensor product deals nicely with
# badly scaled covariates (range of x 5\% of range of z )
require(mgcv)
test1<-function(x,z,sx=0.3,sz=0.4)
{ x<-x*20
(pi**sx*sz)*(1.2*exp(-(x-0.2)^2/sx^2-(z-0.3)^2/sz^2)+
......
......@@ -173,6 +173,7 @@ generalized additive mixed models. Biometrics 62(4):1025-1036
# following shows how tensor pruduct deals nicely with
# badly scaled covariates (range of x 5\% of range of z )
require(mgcv)
test1<-function(x,z,sx=0.3,sz=0.4)
{ x<-x*20
(pi**sx*sz)*(1.2*exp(-(x-0.2)^2/sx^2-(z-0.3)^2/sz^2)+
......
......@@ -51,6 +51,7 @@ Generalized Additive Mixed Models. Biometrics 62(4):1025-1036
\seealso{ \code{\link{te}}, \code{\link{smooth.construct.tensor.smooth.spec}} }
\examples{
require(mgcv)
X <- list(matrix(1:4,2,2),matrix(5:10,2,3))
tensor.prod.model.matrix(X)
......
......@@ -37,6 +37,7 @@ matrix that contains row i of the original matrix.
\examples{
require(mgcv)
X<-matrix(c(1,2,3,1,2,3,4,5,6,1,3,2,4,5,6,1,1,1),6,3,byrow=TRUE)
print(X)
Xu <- uniquecombs(X);Xu
......
......@@ -39,6 +39,7 @@ Wood, S.N. (2006) On confidence intervals for generalized additive models based
\examples{
require(mgcv)
n <- 100
x <- runif(n)
y <- sin(x*2*pi) + rnorm(n)*.2
......
......@@ -6,7 +6,7 @@
#include <stdlib.h>
#include <math.h>
#include <R.h>
#include <R_ext/Linpack.h>
#include <R_ext/Linpack.h> /* only needed for pivoted chol - see note in mgcv_chol */
#include <R_ext/Lapack.h>
#include <R_ext/BLAS.h>
/*#include <dmalloc.h>*/
......@@ -242,6 +242,7 @@ void mgcv_chol(double *a,int *pivot,int *n,int *rank)
rD<-rD[,ind]
L<-mroot(D)
D;t(rD)%*%rD;L%*%t(L)
NOTE: This uses LINPACK - dpstf2.f is LAPACK version, but not in R headers yet!
*/
{ double *work,*p1,*p2,*p;
int piv=1;
......
/* Copyright (C) 2000-20012 Simon N. Wood simon.wood@r-project.org
/* Copyright (C) 2000-2012 Simon N. Wood simon.wood@r-project.org
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
......
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