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="mdcx",m=2)
,
where k
denotes the basis dimension and m+1
is the order of the B-spline basis.smooth.construct.mdcx.smooth.spec(object, data, knots)
s
term in a GAM formula.object$term
. The by
variable is the last element.NULL
then the knot locations are generated automatically."mdcx.smooth"
.smooth.construct.mpi.smooth.spec
,
smooth.construct.mpd.smooth.spec
,
smooth.construct.mdcv.smooth.spec
,
smooth.construct.micx.smooth.spec
,
smooth.construct.micv.smooth.spec
## Monotone decreasing and convex P-splines example
## simulating data...
set.seed(2)
n <- 100
x <- sort(runif(n)*3-1)
f1 <- (x-3)^6 # monotone decreasing and convex smooth
f <- (f1-min(f1))/(max(f1)-min(f1))
y <- f+rnorm(n)*0.20
dat <- data.frame(x=x,y=y)
## fit model ...
b <- scam(y~s(x,k=15,bs="mdcx",m=2),family=gaussian(link="identity"),data=dat)
# UNCONSTRAINED FIT *****************
b1 <- scam(y~s(x,k=15,bs="ps",m=2),family=gaussian(link="identity"),data=dat)
## plot results ...
plot(x,y,xlab="x",ylab="y")
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
Run the code above in your browser using DataLab