scam (version 1.2-5)

smooth.construct.mdcv.smooth.spec: Constructor for monotone decreasing and concave P-splines in SCAMs

Description

This is a special method function for creating smooths subject to both monotone decreasing and concavity 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="mdcv",m=2), where k denotes the basis dimension and m+1 is the order of the B-spline basis.

Usage

# S3 method for mdcv.smooth.spec
smooth.construct(object, data, knots)

Arguments

object

A smooth specification object, generated by an s term in a GAM formula.

data

A data frame or list containing the data required by this term, with names given by object$term. The by variable is the last element.

knots

An optional list containing the knots supplied for basis setup. If it is NULL then the knot locations are generated automatically.

Value

An object of class "mdcv.smooth".

References

Pya, N. and Wood, S.N. (2015) Shape constrained additive models. Statistics and Computing, 25(3), 543-559

See Also

smooth.construct.mpi.smooth.spec, smooth.construct.mpd.smooth.spec, smooth.construct.cx.smooth.spec, smooth.construct.cv.smooth.spec, smooth.construct.mdcx.smooth.spec, smooth.construct.micx.smooth.spec, smooth.construct.micv.smooth.spec

Examples

Run this code
# NOT RUN {
  
# }
# NOT RUN {
## Monotone decreasing and concave P-splines example 
  ## simulating data...
   set.seed(2)
   n <- 100
   x <- sort(runif(n))
   f <- -x^4
   y <- f+rnorm(n)*0.10
   dat <- data.frame(x=x,y=y)
 ## fit model ...
   b <- scam(y~s(x,k=15,bs="mdcv",m=2),family=gaussian(link="identity"),data=dat)

# UNCONSTRAINED FIT *****************
   b1 <- scam(y~s(x,k=15,bs="ps",m=2),family=gaussian(link="identity"),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 
  
# }

Run the code above in your browser using DataLab