Learn R Programming

scam (version 1.2-17)

smooth.construct.tecxcv.smooth.spec: Tensor product smoothing constructor for bivariate function subject to mixed constraints: convexity constraint wrt the first covariate and concavity wrt the second one

Description

This is a special method function for creating tensor product bivariate smooths subject to mixed constraints, convexity constraint wrt the first covariate and concavity wrt the second one. This is built by the mgcv constructor function for smooth terms, smooth.construct. It is constructed from a pair of single penalty marginal smooths which are represented using the B-spline basis functions. This tensor product is specified by model terms such as s(x1,x2,k=c(q1,q2),bs="tecxcv",m=c(2,2)), where q1 and q2 denote the basis dimensions for the marginal smooths.

Usage

# S3 method for tecxcv.smooth.spec
smooth.construct(object, data, knots)

Value

An object of class "tecxcv.smooth". In addition to the usual elements of a smooth class documented under smooth.construct of the mgcv library, this object contains:

p.ident

A vector of 0's and 1's for model parameter identification: 1's indicate parameters which will be exponentiated, 0's - otherwise.

Zc

A matrix of identifiability constraints.

Arguments

object

A smooth specification object, generated by an s term in a GAM formula.

data

A data frame or list containing the values of the elements of object$term, with names given by object$term.

knots

An optional list containing the knots corresponding to object$term. If it is NULL then the knot locations are generated automatically.

Author

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

See Also

smooth.construct.tedmd.smooth.spec smooth.construct.tedecv.smooth.spec

smooth.construct.tedecx.smooth.spec smooth.construct.tecvcv.smooth.spec

smooth.construct.tecxcx.smooth.spec

Examples

Run this code
 if (FALSE) {
## tensor product `tecxcv' example 
  ## simulating data...
   set.seed(5)
   n <- 30
   x1 <- sort(2*runif(n)-1)
   x2 <- sort(2*runif(n)-1)
   f1 <- matrix(0,n,n)
   for (i in 1:n) for (j in 1:n) 
        f1[i,j] <- 2*x1[i]^2 - 4*x2[j]^2  
   f <- as.vector(t(f1))
   y <- f+rnorm(length(f))*.05
   x11 <-  matrix(0,n,n)
   x11[,1:n] <- x1
   x11 <- as.vector(t(x11))
   x22 <- rep(x2,n)
   dat <- list(x1=x11,x2=x22,y=y)
## fit model ...
   b <- scam(y~s(x1,x2,k=c(10,10),bs="tecxcv"), data=dat)
## plot results ...
   par(mfrow=c(2,2),mar=c(4,4,2,2))
   plot(b,se=TRUE)
   plot(b,pers=TRUE,theta = 30, phi = 40)
   plot(y,b$fitted.values,xlab="Simulated data",ylab="Fitted data")
   x11()
   vis.scam(b,theta=30,phi=40)
   ## plotting the truth...
   x11()
   x1 <- seq(min(x1),max(x1),length.out=30)
   x2 <- seq(min(x2),max(x2),length.out=30)
   f1 <- matrix(0,n,n)
   for (i in 1:n) for (j in 1:n) f1[i,j] <- 2*x1[i]^2 - 4*x2[j]^2      
   persp(x1,x2,f1,theta = 30, phi = 40)  
 }

Run the code above in your browser using DataLab