# NOT RUN {
# }
# NOT RUN {
## Monotone decreasing and concave P-splines example
## simulating data...
set.seed(2)
n <- 100
x <- sort(runif(n))
f <- -x^4
y <- f+rnorm(n)*0.10
dat <- data.frame(x=x,y=y)
## fit model ...
b <- scam(y~s(x,k=15,bs="mdcv",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