x1 <- rnorm(100)
x2 <- rnorm(100) + 0.25*x1
x3 <- as.factor(sample(0:1, 100, replace = TRUE))
x4 <- gl(4, 25)
y <- 3*sin(x1) + x2^2 + rnorm(100)
knots.x2 <- quantile(x2, c(0.25,0.5,0.75))
spline1 <- bbs(x1,knots=20,df=4)
attributes(spline1)
spline2 <- bns(x2,knots=knots.x2,df=5)
attributes(spline2)
olsfit <- bols(x3)
attributes(olsfit)
form1 <- y ~ bbs(x1,knots=20,df=4) + bns(x2,knots=knots.x2,df=5)
# example for factors
attributes(bols(x4))
# example for bspatial
x1 <- runif(250,-pi,pi)
x2 <- runif(250,-pi,pi)
y <- sin(x1)*sin(x2) + rnorm(250, sd = 0.4)
spline3 <- bspatial(x1, x2, xknots=12, yknots=12)
attributes(spline3)
form2 <- y ~ bspatial(x1, x2, xknots=12, yknots=12)
# decompose spatial effect into parametric part and deviation with 1 df
form2 <- y ~ bols(x1) + bols(x2) + bols(x1*x2) +
bspatial(x1, x2, xknots=12, yknots=12, center = TRUE, df=1)
# random intercept
id <- factor(rep(1:10, each=5))
raneff <- brandom(id)
attributes(raneff)
# random slope
z <- runif(50)
raneff <- brandom(id, z=z)
attributes(raneff)
# remove intercept from base learner
# and add explicit intercept to the model
tmpdata <- data.frame(x = 1:100, y = rnorm(1:100), int = rep(1, 100))
mod <- gamboost(y ~ bols(int, center = TRUE) + bols(x, center = TRUE),
data = tmpdata, control = boost_control(mstop = 2500))
cf <- unlist(coef(mod))
cf[1] <- cf[1] + mod$offset
cf
coef(lm(y ~ x, data = tmpdata))
Run the code above in your browser using DataLab