# NOT RUN {
## SCOP-splines example with positivity constraint...
## simulating data...
# }
# NOT RUN {
set.seed(3)
n <- 100
x <- seq(-3,3,length.out=100)
f <- dnorm(x)
y <- f + rnorm(n)*0.1
b <- scam(y~s(x,bs="po")-1)
b1 <- scam(y~s(x)) ## unconstrained model
plot(x,y)
lines(x,f)
lines(x,fitted(b),col=2)
lines(x,fitted(b1),col=3)
## two-term example...
set.seed(8)
n <- 200
x1 <- seq(-3,3,length.out=n)
f1 <- 3*exp(-x1^2) ## positively constrained smooth
x2 <- runif(n)*3-1;
f2 <- exp(4*x2)/(1+exp(4*x2)) # monotone increasing smooth
f <- f1+f2
y <- f+rnorm(n)*0.3
dat <- data.frame(x1=x1,x2=x2,y=y)
## fit model, results, and plot...
b2 <- scam(y~s(x1,bs="po")+s(x2,k=15,bs="mpi")-1,data=dat)
summary(b2)
plot(b2,pages=1)
b3 <- scam(y~s(x1,bs="ps")+s(x2,bs="ps"),data=dat) ## unconstrained model
summary(b3)
plot(b3,pages=1)
# }
Run the code above in your browser using DataLab