View source: R/uni.smooth.const-with-po.r
| smooth.construct.mdcx.smooth.spec | R Documentation |
This is a special method function
for creating smooths subject to both monotone decreasing and convexity constraints which is built by
the mgcv constructor function for smooth terms, smooth.construct.
It is constructed using mixed constrained P-splines. This smooth is specified via model terms such as
s(x,k,bs="mdcx",m=2),
where k denotes the basis dimension and m+1 is the order of the B-spline basis.
mdcxBy.smooth.spec works similar to mdcx.smooth.spec but without applying an identifiability constraint ('zero intercept' constraint). mdcxBy.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="mdcxBy"). See an example below.
However a factor by variable requires identifiability constraints, so s(x,by=fac,bs="mdcx") is used in this case.
## S3 method for class 'mdcx.smooth.spec'
smooth.construct(object, data, knots)
## S3 method for class 'mdcxBy.smooth.spec'
smooth.construct(object, data, knots)
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 |
An object of class "mdcx.smooth", "mdcxBy.smooth".
Natalya Pya <nat.pya@gmail.com>
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
smooth.construct.mpi.smooth.spec,
smooth.construct.mpd.smooth.spec,
smooth.construct.cx.smooth.spec,
smooth.construct.cv.smooth.spec,
smooth.construct.mdcv.smooth.spec,
smooth.construct.micx.smooth.spec,
smooth.construct.micv.smooth.spec
## Not run:
## Monotone decreasing and convex SCOP-splines example
## simulating data...
require(scam)
set.seed(2)
n <- 100
x <- sort(runif(n)*3-1)
f <- (x-3)^6/1000 # monotone decreasing and convex smooth
y <- f+rnorm(n)*.4
dat <- data.frame(x=x,y=y)
## fit model ...
b <- scam(y~s(x,k=15,bs="mdcx"),data=dat)
## fit unconstrained model ...
b1 <- scam(y~s(x,k=15,bs="ps"),data=dat)
## plot results ...
plot(x,y,xlab="x",ylab="y")
lines(x,f) ## the true function
lines(x,b$fitted.values,col=2) ## mixed constrained fit
lines(x,b1$fitted.values,col=3) ## unconstrained fit
## numeric 'by' variable example...
set.seed(6)
n <- 100
x <- sort(runif(n)*3-1)
z <- runif(n,-2,3)
f <- (x-3)^6/1000
y <- f*z + rnorm(n)*.4
dat <- data.frame(x=x,z=z,y=y)
b <- scam(y~s(x,k=15,by=z,bs="mdcxBy"),data=dat)
summary(b)
par(mfrow=c(1,2))
plot(b,shade=TRUE)
## unconstrained fit...
b1 <- scam(y~s(x,k=15,by=z),data=dat)
plot(b1,shade=TRUE)
summary(b1)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.