if (FALSE) {
## Monotone decreasing and concave SCOP-splines example
## simulating data...
require(scam)
set.seed(2)
n <- 100
x <- sort(runif(n))
f <- -x^4
y <- f+rnorm(n)*.2
dat <- data.frame(x=x,y=y)
## fit model ...
b <- scam(y~s(x,bs="mdcv"),family=gaussian(),data=dat)
## fit unconstrained model ...
b1 <- scam(y~s(x,bs="ps"),family=gaussian(),data=dat)
## plot results ...
plot(x,y,xlab="x",ylab="y",cex=.5)
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
## numeric 'by' variable example...
set.seed(6)
n <- 100
x <- sort(runif(n))
z <- runif(n,-2,3)
f <- -x^4
y <- f*z + rnorm(n)*0.4
dat <- data.frame(x=x,z=z,y=y)
b <- scam(y~s(x,k=15,by=z,bs="mdcvBy"),data=dat)
summary(b)
par(mfrow=c(1,2))
plot(b,shade=TRUE)
## unconstrained fit...
b1 <- scam(y~s(x,k=15,by=z),data=dat)
plot(b1,shade=TRUE)
summary(b1)
}
Run the code above in your browser using DataLab