I've got a randomForest model object from the R package randomForest and am using the function partialPlot to generate partial dependence plots.

I know that normally one would create these using the full training dataset that went into the randomForest generation. However, I've been playing around to understand the models and have a curious result. When I divide the dataset in two based on values above and below one predictor's mean, then run the partialPlot function separately for each half of the data, the curves look very different. I thought that with a single model, the outcomes should be (at least near) the same. What am I missing here? Reproducible example with a tiny dummy dataset below. Data here: https://drive.google.com/open?id=14kNxo0uP-Ga5hQoOPpDrf-y8mFI030Md

data = read.csv("data.csv")
rf1 = randomForest(data, data$tree, ntree=10)
dry = subset(data, data$riv_dst<=mean(data$riv_dst))
wet = subset(data, data$riv_dst>mean(data$riv_dst))

partialPlot(fit.AcrossSites, Wet, mnth_p_)
partialPlot(fit.AcrossSites, Dry, mnth_p_)
  • 1
    $\begingroup$ Can you please fix your code a bit so it is reproducible? For example, it is unclear, which variable's PDP is examined. In general, as the segmentation of the data is done in a non-random way, there is no reason to expect similar PDP plots. PDP capture the marginal distribution/behaviour of a variable within a sample and given that the two subsamples have definitely non-overlapping supports on at least one of their variables (most) bets are off. $\endgroup$ – usεr11852 Jul 30 '18 at 22:08
  • $\begingroup$ Whoops. Sorry. Fixed the code. Good catch. What do you mean by "supports?" Shouldn't the randomForest model return the same modeled response value regardless of the dataset fed into it? $\endgroup$ – ecologist1234 Jul 30 '18 at 22:51
  • $\begingroup$ Is it because the response variable is generally of different magnitude in the subsets? I'd have thought the respose only determined by the model, given predictor values, but in my full dataset, the plot line is quite similar to the response value. $\endgroup$ – ecologist1234 Jul 30 '18 at 23:21
  • $\begingroup$ Hmm.... One can still not run the code as it is... RF model names are incorrect, dataset names are misspelt and examined variable names are not in string format... That being said, I am able to run the code but I would suggest fixing the seed first (see set.seed()) and then putting on the graph so other people can benefit from the question too. By support I mean the support of the distribution function of the data - very loosely speaking the sample space of it. (Sorry, must sleep tomorrow night again!) $\endgroup$ – usεr11852 Jul 31 '18 at 0:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.