# NOT RUN {
# }
# NOT RUN {
## Monotone decreasing P-splines example
## simulating data...
set.seed(3)
n <- 100
x <- runif(n)*3-1
f <- exp(-1.3*x)
y <- rpois(n,exp(f))
dat <- data.frame(x=x,y=y)
## fit model ...
b <- scam(y~s(x,k=15,bs="mpd",m=2),family=poisson(link="log"),
data=dat,sp=NULL)
# UNCONSTRAINED FIT *****************
b1 <- scam(y~s(x,k=15,bs="ps",m=2),family=poisson(link="log"),
data=dat,sp=NULL)
## plot results ...
plot(x,y,xlab="x",ylab="y")
x1 <- sort(x,index=TRUE)
lines(x1$x,exp(f)[x1$ix]) ## the true function
lines(x1$x,b$fitted.values[x1$ix],col=2) ## monotone fit
lines(x1$x,b1$fitted.values[x1$ix],col=3) ## unconstrained fit
# }
Run the code above in your browser using DataLab