partdep: Partial Dependence Plots

View source: R/partdep.r

partdepR Documentation

Partial Dependence Plots

Description

Produce partial dependence plots for examing each variable's contribution to the predicted response.

Usage

partdep(object, Xvar, Yvar = NULL, fact = FALSE, var.cond = NULL,
  plotmap = FALSE, ylimit = NULL, plot2file = FALSE,
  se.fit = FALSE, too.far = 0.1, sp.id = NULL, palette)

## S3 method for class 'bag'
partdep(object, Xvar, Yvar = NULL, fact = FALSE,
  var.cond = NULL, plotmap = FALSE, ylimit = NULL,
  plot2file = FALSE, se.fit = FALSE, too.far = 0.1, sp.id = NULL,
  palette)

Arguments

object

object of class bag

Xvar

name of variable/s to plot. This can be a single variable e.g. "Len" (1D plot) or the name of two variables e.g. c("Lon", "Lat") for a 2D plot. Currenly only 2D plots for longitude and latitude are implemented.

Yvar

vector of prey names where partial dependence plots are required. If NULL (default) then plots are produced for all prey.

fact

logical. Is the variable a factor? This only works for 1D plots

var.cond

name of the conditioning variable used to condition each plot by.

plotmap

logical. Should a map be plotted? Only useful if longitude and latitude are being plotted as a 2D plot. (default = FALSE)

ylimit

range of values the y-axis takes when plotting. Defaults to the range of the y-data. See par for more details.

plot2file

logical. Should the plots be written to file. If so, the file name defaults to "partdep.pdf" in the current working directory.

se.fit

logical. Should standard errors be produced and plotted on the figures of the 1D plots? (default: FALSE)

too.far

How far to clip the map (Default = 0.1)

sp.id

Species ID (Default = NULL)

palette

colour palette (created using the apc function)

Details

There are many different combinations of arguments for producing 1D and 2D plots. Illustrations of the combinations are shown in the examples section below.

Value

1D and 2D plots of partial dependence.

References

Kuhnert, P.M., Duffy, L. M and Olson, R.J. (2012) The Analysis of Predator Diet and Stable Isotope Data, Journal of Statistical Software, In Prep.

Kuhnert PM, Kinsey-Henderson A, Bartley R, Herr A (2010) Incorporating uncertainty in gully erosion calculations using the random forests modelling approach. Environmetrics 21:493-509. doi:10.1002/env.999

Examples

# Assigning prey colours for default palette
#val <- apc(x = yftdiet, preyfile = PreyTaxonSort, check = TRUE)
#node.colsY <- val$cols
#dietPP <- val$x   # updated diet matrix with Group assigned prey taxa codes

# Fitting the classification tree
#yft.dp <- dpart(Group ~ Lat + Lon + Year + Quarter + SST  + Length, 
#data = dietPP, weights = W, minsplit = 10, cp = 0.001)
#yft.pr <- prune(yft.dp, se = 1)
#plot(yft.pr, node.cols = node.colsY)

# Bagging
# Bagging with NO spatial bootstrapping
# yft.bag <- bagging(Group ~ Lat + Lon + Year + Quarter + SST  + Length, 
#            data = dietPP, weights = W, minsplit = 50,
#             cp = 0.001, nBaggs = 500, predID = "TripSetPredNo")
            
# 1D plots based on covariates in tree model
#partdep(object = yft.bag, Xvar = "Length")
#partdep(object = yft.bag, Xvar = "Length", se.fit = TRUE)
#partdep(object = yft.bag, Xvar = "SST")
#partdep(object = yft.bag, Xvar = "Quarter", fact = TRUE, se.fit = TRUE)
#partdep(object = yft.bag, Xvar = "Year", fact = TRUE)

# 2D plots of Longitude and Latitude
#partdep(object = yft.bag, Xvar = c("Lon", "Lat"), plotmap = TRUE)
# 2D plots of Longitude and Latitude conditioning on Year
#partdep(object = yft.bag, Xvar = c("Lon", "Lat"), plotmap = TRUE, 
#               leg.pos="topleft", too.far = 0.05, sp.id = "F.Ost")
#partdep(object = yft.bag, Xvar = c("Lon", "Lat"), var.cond = list(Year = 2004),
#     too.far = 0.05, plotmap = TRUE, sp.id = "F.Ost")

# 2D plots of SST and Length
#partdep(object = yft.bag, Xvar = c("SST", "Length"))



pkuhnert/diet documentation built on June 10, 2025, 2:59 a.m.