gam
model formulae. The function does not evaluate a (spline)
smooth - it exists purely to help set up a model using spline based smooths.s(..., k=-1,fx=FALSE,bs="tp",m=NA,by=NA,xt=NULL,id=NULL,sp=NULL)
k
should not be less than the dimension of the
null space of the penalty for the term (TRUE
) or a penalized regression spline (FALSE
)."tp"
for thin plate regression spline, "cr"
for cubic regression spline).
see smooth.terms
NA
signals
autoinitialization. Only some smooth classes use this. The "ps"
clby
v"tp"
basis.id
then they will have the same smoothing paramsters, and, by default,
xx.smooth.spec
object, where xx
is a basis identifying code given by
the bs
argument of s
. These smooth.spec
objects define smooths and are turned into
bases and penalties by smooth.construct
method functions. The returned object contains the following items:
by
variable as text ("NA"
for none).xt
.NULL
for no linkage.NULL
.smooth.construct
.Wood S.N. (2006) Generalized Additive Models: An Introduction with R. Chapman and Hall/CRC Press.
te
, gam
, gamm
# example utilising `by' variables
library(mgcv)
set.seed(0)
n<-200;sig2<-4
x1 <- runif(n, 0, 1);x2 <- runif(n, 0, 1);x3 <- runif(n, 0, 1)
fac<-c(rep(1,n/2),rep(2,n/2)) # create factor
fac.1<-rep(0,n)+(fac==1);fac.2<-1-fac.1 # and dummy variables
fac<-as.factor(fac)
f1 <- exp(2 * x1) - 3.75887
f2 <- 0.2 * x1^11 * (10 * (1 - x1))^6 + 10 * (10 * x1)^3 * (1 - x1)^10
f<-f1*fac.1+f2*fac.2+x2
e <- rnorm(n, 0, sqrt(abs(sig2)))
y <- f + e
# NOTE: smooths will be centered, so need to include fac in model....
b<-gam(y~fac+s(x1,by=fac)+x2)
plot(b,pages=1)
Run the code above in your browser using DataLab