Learn R Programming

scam (version 1.0)

smooth.construct.mpd.smooth.spec: Constructor for monotone decreasing P-splines in SCAMs

Description

This is a special method function for creating smooths subject to monotone decreasing constraints which is built by the mgcv constructor function for smooth terms, smooth.construct. It is constructed using monotonic P-splines. This smooth is specified via model terms such as s(x,k,bs="mpd",m=2), where k denotes the basis dimension and m+1 is the order of the B-spline basis.

Usage

smooth.construct.mpd.smooth.spec(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 "mpd.smooth".

References

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.mdcv.smooth.spec, smooth.construct.mdcx.smooth.spec, smooth.construct.micv.smooth.spec, smooth.construct.micx.smooth.spec

Examples

Run this code
## Monotone decreasing P-splines example 
  ## simulating data...
   set.seed(3)
   n <- 100
   x <- runif(n)*3-1
   f <- exp(-1.3*x)
   y <- rpois(n,exp(f))
   dat <- data.frame(x=x,y=y)
 ## fit model ...
   b <- scam(y~s(x,k=15,bs="mpd",m=2),family=poisson(link="log"),
       data=dat,sp=NULL)

# UNCONSTRAINED FIT *****************
   b1 <- scam(y~s(x,k=15,bs="ps",m=2),family=poisson(link="log"),
         data=dat,sp=NULL)

## plot results ...
   plot(x,y,xlab="x",ylab="y")
   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)  ## monotone fit 
   lines(x1$x,b1$fitted.values[x1$ix],col=3) ## unconstrained fit

Run the code above in your browser using DataLab