smooth.construct.micx.smooth.spec {scam} | R Documentation |
Constructor for monotone increasing and convex P-splines in SCAMs
Description
This is a special method function
for creating smooths subject to both monotone increasing and convexity constraints which is built by
the mgcv
constructor function for smooth terms, smooth.construct
.
It is constructed using the mixed constrained P-splines. This smooth is specified via model terms such as
s(x,k,bs="micx",m=2)
,
where k
denotes the basis dimension and m+1
is the order of the B-spline basis.
micxBy.smooth.spec
works similar to micx.smooth.spec
but without applying an identifiability constraint ('zero intercept' constraint). micxBy.smooth.spec
should be used when the smooth term has a numeric by
variable that takes more than one value. In such cases, the smooth terms are fully identifiable without a 'zero intercept' constraint, so they are left unconstrained. This smooth is specified as
s(x,by=z,bs="micvBy")
. See an example below.
However a factor by
variable requires identifiability constraints, so s(x,by=fac,bs="micx")
is used in this case.
Usage
## S3 method for class 'micx.smooth.spec'
smooth.construct(object, data, knots)
## S3 method for class 'micxBy.smooth.spec'
smooth.construct(object, data, knots)
Arguments
object |
A smooth specification object, generated by an |
data |
A data frame or list containing the data required by this term,
with names given by |
knots |
An optional list containing the knots supplied for basis setup.
If it is |
Value
An object of class "micx.smooth"
, "micxBy.smooth"
.
Author(s)
Natalya Pya <nat.pya@gmail.com>
References
Pya, N. and Wood, S.N. (2015) Shape constrained additive models. Statistics and Computing, 25(3), 543-559
Pya, N. (2010) Additive models with shape constraints. PhD thesis. University of Bath. Department of Mathematical Sciences
See Also
smooth.construct.mpi.smooth.spec
,
smooth.construct.cx.smooth.spec
,
smooth.construct.cv.smooth.spec
,
smooth.construct.mdcv.smooth.spec
,
smooth.construct.mdcx.smooth.spec
,
smooth.construct.micv.smooth.spec
,
smooth.construct.mpd.smooth.spec
Examples
## Not run:
## Monotone increasing and convex SCOP-splines example
## simulating data...
set.seed(1)
n <- 100
x <- runif(n)*2
f <- 5*x^2/8
y <- rpois(n,exp(f))
dat <- data.frame(x=x,y=y)
## fit model ...
b <- scam(y~s(x,bs="micx"),family=poisson,data=dat)
## fit unconstrained model ...
b1 <- scam(y~s(x,bs="cr"),family=poisson,data=dat)
## plot results ...
plot(x,y,xlab="x",ylab="y",cex=.5)
x1 <- sort(x,index=TRUE)
lines(x1$x,exp(f)[x1$ix]) ## the true function
lines(x1$x,b$fitted.values[x1$ix],col=2) ## mixed constrained fit
lines(x1$x,b1$fitted.values[x1$ix],col=3) ## unconstrained fit
## numeric 'by' variable example...
set.seed(10)
n <- 100
x <- runif(n)*2
f <- x^2
z <- runif(n,-2,3)
y <- f*z + rnorm(n)*0.4
dat <- data.frame(x=x,z=z,y=y)
b <- scam(y~s(x,by=z,bs="micxBy"),data=dat)
summary(b)
par(mfrow=c(1,2))
plot(b,shade=TRUE)
## unconstrained fit...
b1 <- scam(y~s(x,by=z),data=dat)
plot(b1,shade=TRUE)
summary(b1)
## End(Not run)