plot_pd: Plot partial dependence

View source: R/plot_pd.R

plot_pdR Documentation

Plot partial dependence

Description

Plot the partial dependence functions (i.e., marginal effects) for the predictors in a model.

Usage

plot_pd(pd)

Arguments

pd

Data frame containing the partial dependence effect as returned by get_pd.

Value

ggplot object showing the partial dependence effect in pd.

Examples

## Not run: 
data('mtpl_be')
features <- setdiff(names(mtpl_be), c('id', 'nclaims', 'expo', 'long', 'lat'))
set.seed(12345)
gbm_fit <- gbm::gbm(as.formula(paste('nclaims ~',
                               paste(features, collapse = ' + '))),
                    distribution = 'poisson',
                    data = mtpl_be,
                    n.trees = 50,
                    interaction.depth = 3,
                    shrinkage = 0.1)
gbm_fun <- function(object, newdata) mean(predict(object, newdata, n.trees = object$n.trees, type = 'response'))
gbm_fit %>% get_pd(var = 'ageph',
                   grid = 'ageph' %>% get_grid(data = mtpl_be),
                   data = mtpl_be,
                   subsample = 10000,
                   fun = gbm_fun) %>%
            plot_pd

## End(Not run)

henckr/maidrr documentation built on July 27, 2023, 3:17 p.m.