# NOT RUN {
## Simulate data.
set.seed(123)
d <- GAMart()
## Estimate model.
f <- num ~ x1 + x2 + x3 + lon + lat +
s(x1) + s(x2) + s(x3) + s(lon) + s(lat) + te(lon,lat)
b <- bamlss(f, data = d, optimizer = boost,
sampler = FALSE, scale.d = TRUE, nu = 0.01,
maxit = 1000, plot = FALSE)
## Plot estimated effects.
plot(b)
## Print and plot the boosting summary.
boost.summary(b, plot = FALSE)
boost.plot(b, which = 1)
boost.plot(b, which = 2)
boost.plot(b, which = 3, name = "mu.s.te(lon,lat).")
## Extract estimated parameters for certain
## boosting iterations.
parameters(b, mstop = 1)
parameters(b, mstop = 100)
## Also works with predict().
head(do.call("cbind", predict(b, mstop = 1)))
head(do.call("cbind", predict(b, mstop = 100)))
## Another example using the modified liklihood
## bootsing algorithm.
f <- list(
num ~ x1 + x2 + x3 + lon + lat +
s(x1) + s(x2) + s(x3) + s(lon) + s(lat) + te(lon,lat),
sigma ~ x1 + x2 + x3 + lon + lat +
s(x1) + s(x2) + s(x3) + s(lon) + s(lat) + te(lon,lat)
)
b <- bamlss(f, data = d, optimizer = boostm,
sampler = FALSE, scale.d = TRUE, nu = 0.05,
maxit = 400, stop.criterion = "AIC", force.stop = FALSE)
## Plot estimated effects.
plot(b)
## Plot AIC and log-lik contributions.
boost.plot(b, "AIC")
boost.plot(b, "loglik.contrib")
## Out-of-sample selection of model terms.
set.seed(123)
d <- GAMart(n = 5000)
## Split data into training and testing
i <- sample(1:2, size = nrow(d), replace = TRUE)
d.test <- subset(d, i == 1)
d.train <- subset(d, i == 2)
## Model formula
f <- list(
num ~ s(x1) + s(x2) + s(x3),
sigma ~ s(x1) + s(x2) + s(x3)
)
## Create model frame for out-of-sample selection.
sm <- boost.frame(f, train = d.train, test = d.test, family = "gaussian")
## Out-of-sample selection function.
sfun <- function(parameters) {
sm$parameters <- parameters
p <- predict(sm, type = "parameter")
-1 * sum(sm$family$d(d.test$num, p, log = TRUE))
}
## Start boosting with out-of-sample negative
## log-likelihood selection of model terms.
b <- bamlss(f, data = d.train, sampler = FALSE, optimizer = boost,
selectfun = sfun, always = "best")
## Plot curve of negative out-of-sample log-likelihood.
boost.plot(b, which = "user")
# }
Run the code above in your browser using DataLab