Learn R Programming

scam (version 1.0)

smooth.construct.micv.smooth.spec: Constructor for monotone increasing and concave P-splines in SCAMs

Description

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

Usage

smooth.construct.micv.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 "micv.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.micx.smooth.spec, smooth.construct.mpd.smooth.spec

Examples

Run this code
## Monotone increasing and concave P-splines example 
  ## simulating data...
   set.seed(3)
   n <- 100
   x <- sort(runif(n)*99+1)
   f1 <- log(x)
   f <- (f1-min(f1))/(max(f1)-min(f1))
   y <- f+rnorm(n)*0.10
   dat <- data.frame(x=x,y=y)
 ## fit model ...
   b <- scam(y~s(x,k=15,bs="micv",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