print: Print from a dpart object

View source: R/print.r

printR Documentation

Print from a dpart object

Description

Either prints a dpart object or prints output from a node selected from a rpart tree.

Usage

print(x, ...)

## S3 method for class 'dpart'
print(x, setID = NULL, digits = getOption("digits"),
  file = "diet_tree_summary.csv", ...)

## S3 method for class 'grab'
print(x, ...)

Arguments

x

fitted model object of class dpart OR object of class grab.

...

arguments to be passed to or from other methods.

setID

the set identification number used to summarise the output. Defaults to NULL.

digits

the number of digits of numbers to print

file

file name where to output summary results. (Output too big to print to screen).

Details

This function is a method for the generic function print for class "dpart". It can be invoked by calling print for an object of the appropriate class, or directly by calling print.dpart. The loss is computed as the deviance at a node divided by the number of predators appearing at a node and ranges between 0 and 1. The loss is a measure of the diversity of prey eaten by predators at the node, where values near 0 indicate low diversity and values near 1 indicate high diversity.

print.dpart Summary of the tree is provided as a csv file with the following column headings:

  • nodenode number

  • nobsnumber of observations in each node

  • nsetsnumber of sets in each node if a setID was provided otherwise, NA

  • npredatornumber of predators in each node

  • npreynumber of prey in each node

  • devnode deviance

  • lossnode loss

  • splitthe split that derived each node

  • pclassthe predicted classification for each node

print.grab Summarises the node selected into the following: Node ID, Number of observations, Number of sets, Number of predators, Number of prey, deviance, expected loss and predicted class.

The output is printed to a .csv file

Examples


# Example 1: Printing output from dpart

# 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)
 plot(yft.dp, node.cols = node.colsY)
 summary(yft.dp)
 print(yft.dp, setID = "TripSetNo")
                                    
# Example 2: Printing nodes from the tree

# 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)                   
# Exploring Nodes: This suite of graphics is interactive and therefore will not be run. 
# When run, the code will ask you to select a node for
# viewing.

# Exploring nodes of the tree - single page
## Not run: 
val <- grab(object = yft.pr, LatID = "Lat", LonID = "Lon", setID = "TripSetNo", 
            node.cols = node.colsY, cex = 1, mapxlim = c(-125, -75), mapylim = c(0, 30),
            mapcol = "gold3", pos = "topleft")
 val

## End(Not run)

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