View source: R/uni.smooth.const-with-po.r
smooth.construct.po.smooth.spec | R Documentation |
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.
## S3 method for class 'po.smooth.spec'
smooth.construct(object, data, knots)
object |
A smooth specification object, generated by an |
data |
A data frame or list containing the data required by this term,
with names given by |
knots |
An optional list containing the knots supplied for basis setup.
If it is |
An object of class "po.smooth"
.
Natalya Pya <nat.pya@gmail.com>
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
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
## 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)) ## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.