# NOT RUN {
# }
# NOT RUN {
## Monotone increasing and convex P-splines example
## simulating data...
set.seed(22)
n <- 100
x <- runif(n)*2
f <- x^2
y <- rpois(n,exp(f))
dat <- data.frame(x=x,y=y)
## fit model ...
b <- scam(y~s(x,k=15,bs="micx",m=2),family=poisson(link="log"),
data=dat,sp=NULL,not.exp=FALSE)
# UNCONSTRAINED FIT *****************
b1 <- scam(y~s(x,k=15,bs="cr",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) ## mixed constrained fit
lines(x1$x,b1$fitted.values[x1$ix],col=3) ## unconstrained fit
# }
Run the code above in your browser using DataLab