# NOT RUN {
# }
# NOT RUN {
## 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