0
$\begingroup$

I am looking into the mboost package in R for creating GAM models. Below is code for creating a very simple GAM model with tree stumps on the mtcars data set.

library(mboost)

my_model = mboost(formula = mpg ~ cyl + disp + hp,
                  data = mtcars, 
                  baselearner = "btree", 
                  control = boost_control(mstop = 1000, nu = 0.1))

par(mfrow = c(1,3))
plot(my_model)

The resulting shape plots for the three functions $f_{cyl}, f_{disp}, f_{hp}$ look like this: enter image description here

I can now use the model to predict new instances by calling predict(mymodel, newdata). However, is there a way to predict by using one of the shape functions at the time? In practice, this means that I would like to call something like predict(f_cyl, newdata), predict(f_disp, newdata) or predict(f_hp, newdata) where f_cyl, f_disp and f_hp are the shape functions that together make up the GAM.

$\endgroup$

1 Answer 1

0
$\begingroup$

The solution was to use predict.mboost(object = my_model, newdata = mtcars, which = 1), in order to get predictions only from shape function 1 (and which = 2 to get predictions only from shape function 2, etc.).

Now these predictions can be stored in a data frame and can plotted in ggplot2, or used for other purposes.

Thanks to Dr. Benjamin Hofner for pointing this out to me!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.