predict: Predict from a dpart Object

View source: R/predict.r

predictR Documentation

Predict from a dpart Object

Description

Forms predictions from an object of class dpart. Options are to produce predicted probabilities or predicted classificaitons.

Usage

predict(object, ...)

## S3 method for class 'dpart'
predict(object, newdata = list(), type = c("prob",
  "class"), node.cols = NULL, plot = TRUE, pred.type = "obs",
  predatorID = NULL, cex = 1, ...)

Arguments

object

object of class dpart

...

other arguments to pass into the function

newdata

optional data set to predict on.

type

either "prob" or "class" to specify probabilities or classifications.

node.cols

node.cols

plot

logical. Produce a plot of the predictions if TRUE otherwise just write the predictions out to file.

pred.type

either "obs" or "predator" to indicate whether predictions are to be generated for each observation or each predator, respectively.

predatorID

predator identification label. Required when pred.type = "predator"

cex

numeric. Size of plotting characters and labels.

Value

Predicted probabilities for each observation or each predator, if pred.type = "predator" was specified. Predicted classifications if type = "class" was specified.

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.

Examples

# Load data
#data(yftdiet)  
# Load the prey taxa data
#data(PreyTaxonSort)

# 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)
                                    
# Pruning the tree
#yft.pr <- prune(yft.dp, se = 1)                   

# Predictions
# predict distribution of prey composition for each predator
#yft.predator <- predict(yft.pr, type = "prob", pred.type = "predator",
#                          predatorID = "TripSetNo")
                          
# predict distribution of prey composition for each observation
#yft.pred.obs <- predict(yft.pr, type = "prob")
                          
# predict classification  for each observation in the dataset
#yft.predC <- predict(yft.pr, type = "class")   # predicted 
#classification
         

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