Skip to content

Instantly share code, notes, and snippets.

@zmjones
zmjones / partial_dependence_party.R
Last active August 29, 2015 14:04
parallel calculation of marginal or joint dependence of explanatory variables from a party random forest
pkgs <- c("party", "parallel")
invisible(lapply(pkgs, require, character.only = TRUE))
partial_dependence <- function(fit, ivar, cores = 1, ...) {
## calculates the partial dependence of the response on explanatory variable(s)
## fit must be a party object
## ivar must be a character vector of length >= 1 all of which
## exist in the dataframe used to fit the model
## if the length of ivar > 1, joint dependence is calculated
df <- data.frame(get("input", fit@data@env), get("response", fit@data@env))