# NOT RUN {
## Simulate data.
set.seed(123)
d <- GAMart()
## Estimate model.
f <- num ~ s(x1) + s(x2) + s(x3) + s(lon,lat)
## Function for evaluation of hold out sample
## criterion to find the optimum mstop.
fmstop <- function(model, data) {
p <- predict(model, newdata = data, model = "mu")
mse <- NULL
for(i in 1:nrow(model$parameters))
mse <- c(mse, mean((data$num - p[, i])^2))
list("MSE" = mse, "mstop" = which.min(mse))
}
## Bootstrap boosted models.
b <- bboost(f, data = d, n = 50, cores = 3, fmstop = fmstop)
## Plot hold out sample MSE.
bboost.plot(b)
## Predict for each bootstrap sample.
nd <- data.frame("x2" = seq(0, 1, length = 100))
p <- predict(b, newdata = nd, model = "mu", term = "x2")
plot2d(p ~ x2, data = nd)
# }
Run the code above in your browser using DataLab