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

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

smooth.construct.micv.smooth.specR Documentation

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.

micvBy.smooth.spec works similar to micv.smooth.spec but without applying an identifiability constraint ('zero intercept' constraint). micvBy.smooth.spec should be used when the smooth term has a numeric by variable that takes more than one value. In such cases, the smooth terms are fully identifiable without a 'zero intercept' constraint, so they are left unconstrained. This smooth is specified as s(x,by=z,bs="micvBy"). See an example below.

However a factor by variable requires identifiability constraints, so s(x,by=fac,bs="micv") is used in this case.

Usage

## S3 method for class 'micv.smooth.spec'
smooth.construct(object, data, knots)
## S3 method for class 'micvBy.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 "micv.smooth", "micvBy.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.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.micx.smooth.spec, smooth.construct.mpd.smooth.spec

Examples

 ## Not run: 
## Monotone increasing and concave SCOP-splines example 
  ## simulating data...
   set.seed(3)
   n <- 100
   x <- sort(runif(n)*99+1)
   f <- log(x)/2
   y <- f+rnorm(n)*.3
   dat <- data.frame(x=x,y=y)
   ## fit model ...
   b <- scam(y~s(x,k=15,bs="micv"), data=dat)
   summary(b)
   # fit unconstrained model ...
   b1 <- scam(y~s(x,k=15,bs="ps"),data=dat)
   ## plot results ...
   plot(x,y,xlab="x",ylab="y",cex=.5)
   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 

 ## numeric 'by' variable example... 
 set.seed(3)
 n <- 100
 x <- sort(runif(n)*99+1)
 f <- log(x)/2
 z <- runif(n,-2,3)
 y <- f*z + rnorm(n)*0.3
 dat <- data.frame(x=x,z=z,y=y)
 b <- scam(y~s(x,k=15,by=z,bs="micvBy")-1,data=dat)
 summary(b)
 par(mfrow=c(1,2))
 plot(b,shade=TRUE)
 ## unconstrained fit...
 b1 <- scam(y~s(x,k=15,by=z)-1,data=dat)
 plot(b1,shade=TRUE)
 summary(b1)
  
## End(Not run)

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