Learn R Programming

scam (version 1.2-5)

smooth.construct.micx.smooth.spec: 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.

Usage

# S3 method for micx.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 "micx.smooth".

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

Run this code
# NOT RUN {
 
# }
# NOT RUN {
## Monotone increasing and convex P-splines example 
  ## simulating data...
   set.seed(22)
   n <- 100
   x <- runif(n)*2
   f <- x^2
   y <- rpois(n,exp(f))
   dat <- data.frame(x=x,y=y)
 ## fit model ...
   b <- scam(y~s(x,k=15,bs="micx",m=2),family=poisson(link="log"),
       data=dat,sp=NULL,not.exp=FALSE)

# UNCONSTRAINED FIT *****************
   b1 <- scam(y~s(x,k=15,bs="cr",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)  ## mixed constrained fit 
   lines(x1$x,b1$fitted.values[x1$ix],col=3) ## unconstrained fit 
 
# }

Run the code above in your browser using DataLab