library(scam)
set.seed(2)
n <- 200
x1 <- runif(n)*4-1; x2 <- runif(n)*3-1;
f1 <- function(x) exp(4*x)/(1+exp(4*x)) # monotone increasing smooth
f2 <- function(x) exp(-3*x)/15 # monotone decreasing and convex smooth
f <- f1(x1) + f2(x2)
y <- f+ rnorm(n)*0.2
dat <- data.frame(x1=x1,x2=x2,y=y)
b <- scam(y~ s(x1,bs="mpi")+s(x2,bs="mdcx"),data=dat)
plot(b,pages=1)
scam.check(b)
# \donttest{
## binomial model...
set.seed(4)
n <- 400
scale <- 3.3
x0 <- runif(n, 0, 1)
f0 <- function(x) 2 * sin(pi * x)
x1 <- runif(n)*4-1
f1 <- function(x) exp(4*x)/(1+exp(4*x))
f <- f0(x0) + f1(x1)
f <- (f-2)*scale
g <- binomial()$linkinv(f)
y <- rbinom(g,1,g)
dat <- data.frame(y=y,x0=x0,x1=x1)
b1 <- scam(y~s(x0)+s(x1,bs="mpi"),family=binomial,data=dat)
scam.check(b1)
## residuals plots using randomized quantile residuals...
scam.check(b1, type="rquantile")
## Residuals vs linear predictor for four realizations of the quantile residuas...
old.par <- par(mfrow=c(2,2))
plot(b1$linear.predictors,residuals(b1, type="rquantile"))
plot(b1$linear.predictors,residuals(b1, type="rquantile"))
plot(b1$linear.predictors,residuals(b1, type="rquantile"))
plot(b1$linear.predictors,residuals(b1, type="rquantile"))
par(old.par)
# }
Run the code above in your browser using DataLab