if (FALSE) {
beta=function(l,m,x)
return(gamma(l+m)*(gamma(l)*gamma(m))^(-1)*x^(l-1)*(1-x)^(m-1))
f1 = function(x) return((0.6*beta(30,17,x)+0.4*beta(3,11,x))*1/0.958)
f2 = function(z) return((sin(2*pi*(z-0.5))^2)*1/.3535)
f3 = function(z)
return((exp(-400*(z-0.6)^2)+
5/3*exp(-500*(z-0.75)^2)+2*exp(-500*(z-0.9)^2))*1/0.549)
center=function(x) return(x-mean(x))
set.seed(1)
N <- 500
x1 = runif(N,0,1)
x2 = runif(N,0,1)
x3 = runif(N,0,1)
kn1 <- default.knots(x1,40)
kn2 <- default.knots(x2,40)
kn3 <- default.knots(x3,40)
kn.var3 <- default.knots(kn3,5)
y <- f1(x1)+f2(x2)+f3(x3)+0.3*rnorm(N)
# fit model with last smoothing parameter adaptive
fit2b= asp2(y~f(x1, basis="os", degree=3, knots=kn1, adap=FALSE)
+f(x2, basis="os", degree=3, knots=kn2, adap=FALSE)
+f(x3, basis="os", degree=3, knots=kn3, adap=TRUE,
var.knots=kn.var3, var.basis="os", var.degree=3),
niter = 20, niter.var = 200)
# compute 95
# You could skip this and use "fit2b" indstead of "scb2b" later on,
# however, if N is large, computing the SCBs various times can take
# some time if you don't need fitted values and bounds for all covariate points
# (can be computationally intensive due to large matrix dimensions),
# set calc.stdev=F such that these are not computed.
scb2b<- scbM(fit2b,calc.stdev=FALSE)
plot(scb2b,pages=1)
# plot first derivative of f(x1)
scb2bdrv<- scbM(fit2b,drv=1,calc.stdev=FALSE)
plot(scb2bdrv,select=1)
#the following would give the same result
#plot(fit2b,select=1,drv=1)
#different style
plot(scb2bdrv,select=1,scb.lty="blank", shade=TRUE,
shade.col="steelblue")
}
Run the code above in your browser using DataLab