smooth.construct.po.smooth.spec: Constructor for monotone increasing P-splines in SCAMs

View source: R/uni.smooth.const-with-po.r

smooth.construct.po.smooth.specR Documentation

Constructor for monotone increasing P-splines in SCAMs

Description

This is a special method function for creating univariate smooths subject to a positivity constraint 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 suach as s(x,k,bs="po",m=2), where k denotes the basis dimension and m+1 is the order of the B-spline basis.

Note: Models that include this smooth should not have an intercept. See examples below.

Usage

## S3 method for class 'po.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 "po.smooth".

Author(s)

Natalya Pya <nat.pya@gmail.com>

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

Examples

 
##  SCOP-splines example with positivity constraint... 
  ## simulating data...
## Not run: 
   require(scam)
   set.seed(3)
   n <- 100
   x <- seq(-3,3,length.out=100)
   f <- dnorm(x) 
   y <- f + rnorm(n)*0.1  
   b <- scam(y~s(x,bs="po")-1)
  
   b1 <- scam(y~s(x)) ## unconstrained model
   plot(x,y)
   lines(x,f)
   lines(x,fitted(b),col=2)
   lines(x,fitted(b1),col=3)

  ## two-term example...
  set.seed(3)
  n <- 200
  x1 <- seq(-3,3,length.out=n)
  f1 <- 3*exp(-x1^2) ## positively constrained smooth
  x2 <- runif(n)*3-1;
  f2 <- exp(4*x2)/(1+exp(4*x2)) # monotone increasing smooth 
  f <- f1+f2
  y <- f+rnorm(n)*0.3
  dat <- data.frame(x1=x1,x2=x2,y=y)
  ## fit model, results, and plot...
  b2 <- scam(y~s(x1,bs="po")+s(x2,bs="mpi")-1,data=dat)
  summary(b2)
  plot(b2,pages=1)

  b3 <- scam(y~s(x1,bs="ps")+s(x2,bs="ps"),data=dat) ## unconstrained model
  summary(b3)
  plot(b3,pages=1) 
 
## End(Not run) 

scam documentation built on April 14, 2023, 5:12 p.m.