View source: R/bivar.smooth.const.R
| smooth.construct.tedi.smooth.spec | R Documentation |
This is a special method function for constructing tensor product bivariate smooths that are monotonically decreasing in the first covariate and monotonically increasing in the second.
The smooths are specified using model terms such as
s(x1, x2, k = c(q1, q2), bs = "tedi", m = c(2, 2)),
where q1 and q2 denote the basis dimensions of the
marginal smooths, which are represented using B-spline basis functions.
The order of the marginal B-spline basis is given by m_j + 1.
## S3 method for class 'tedi.smooth.spec'
smooth.construct(object, data, knots)
object |
A smooth specification object, generated by an |
data |
A data frame or list containing the values of the elements of |
knots |
An optional list containing the knots corresponding to |
An object of class "tedi.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. |
Natalya Pya <nat.pya@gmail.com>
Pya, N. and Wood, S.N. (2015) Shape constrained additive models. Statistics and Computing, 25(3), 543-559
smooth.construct.tedmd.smooth.spec,
smooth.construct.tedmi.smooth.spec,
smooth.construct.teid.smooth.spec,
## tensor product `tedi' example
require(scam)
simu <- function(x,z) {-exp(4*x)/(1+exp(4*x))+ 2*exp(z-0.5) }
xs <- seq(-1,3,length=30); zs <- seq(0,1,length=30)
pr <- data.frame(x=rep(xs,30),z=rep(zs,rep(30,30)))
truth <- matrix(simu(pr$x,pr$z),30,30)
set.seed(2)
n <- 500
x <- runif(n)*4-1
z <- runif(n)
f <- simu(x,z)
y <- f + rnorm(n)*.2
## fit model ...
b <- scam(y~s(x,z,k=10,bs="tedi"))
summary(b)
old.par <- par(mfrow=c(2,2),mar=c(4,4,2,2))
plot(b,se=TRUE)
plot(b,pers=TRUE,theta = 40, phi = 40);title("tedi")
plot(y,b$fitted.values,xlab="Simulated data",ylab="Fitted data",pch=".",cex=3)
persp(xs,zs,truth,theta = 40, phi = 40);title("truth")
par(old.par)
vis.scam(b,theta = 40, phi = 40)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.