Transcription of Package ‘rpart.plot’ - The Comprehensive R Archive Network
1 Package August 22, 'rpart' Models: An Enhanced Version of ' 'AuthorStephen MilborrowMaintainerStephen (>= ), rpart (>= )Suggestsearth (>= )DescriptionPlot 'rpart' models. Extends () and ()in the 'rpart' 05:00:02 UTCR topics documented:prp ..2ptitanic .. 25 Index2612prpprpPlot an rpart function combines and therpartpackage. For anoverview, please see the Package vignette Plotting rpart trees with the a simplified interface to this function. First-time users than this arguments of this function are a superset of those some of the argumentshave different defaults. See page for a table showing the different defaults.(The defaults are different for historical reasons: for backwards compatibility the defaults ofprphaven t changed, whereas the defaults changed whentype="auto" introduced in version of this Package .)Usageprp(x=stop("no'x'arg"),typ e=0, extra=0, under=FALSE, ,nn=FALSE, ni=FALSE, yesno=TRUE,branch=if( ) 1 else.)
2 2,uniform=TRUE, left=TRUE, xflip=FALSE, yflip=FALSE,digits=2, varlen=-8, faclen=3, roundint=TRUE,cex=NULL, tweak=1, , ,compress=TRUE, ycompress=uniform,Margin=0, space=1, gap=NULL,snip=FALSE, , trace=FALSE, , , , , ,round=NULL, , , prefix="", suffix="", xsep=NULL, , , , , , , , , , , , , , , "", , "", ,facsep=",", eq=" = ", lt=" < ", ge=" >= ", ( ( )) 1 else "gray", , , , , , , , , "", , , , , , , "yes", "no", , ,FUN="text",nspace=branch, minbranch=.3, , , (type == 5), "",yshift=0, yspace=space, , , , , , , , , , ,ygap=gap/2, , ,xcompact=TRUE, ycompact=uniform, , , , , , , ( , 2), , , , , ,..)ArgumentsxAnrpartobject. The only required of plot . Possible values:0 Default. Draw a split label at each split and a node label at each all nodes, not just leaves. Similar sall= draw the split labels below the node labels.
3 Similar to the plots inthe CART separate split labels for the left and right label all nodes, not just leaves. Similar sfancy= New in version the split variable name in the interior extra information at the nodes. Possible values:"auto"(case insensitive)Automatically select a value based on the model type, as follows:extra=106class model with a binary response4prpextra=104class model with a response having more than two levelsextra=100other models0 Default. No extra the number of observations that fall in the node (per class forclassobjects; prefixed by the number of events forpoissonandexpmodels). models: display the classification rate at the node, expressed as thenumber of correct classifications and the number of observations in the and exp models: display the number of models: misclassification rate at the node, expressed as the number ofincorrect classifications and the number of observations in the models: probability per class of observations in the node (conditionedon the node, sum across a node is 1).
4 5 Class models: like4but don t display the fitted models: the probability of the second class only. Useful for models: like6but don t display the fitted models: the probability of the fitted models: The probability relative toallobservations the sum of theseprobabilities across all leaves is 1. This is in contrast to the options above, whichgive the probability relative to observations fallingin the node the sum of theprobabilities across the node is New in version models: Like9but display the probability ofthe second class only. Useful for binary New in version models: Like10but don t display the fitted class.+100 Add100to any of the above to also display the percentage of observationsin the node. For exampleextra=101displays the number and percentage of ob-servations in the node. Actually, it s a weighted percentage using theweightspassed : , by defaultprpuses its own routine for generatingnode labels (not the function attached to the object).
5 See only ifextra > 0. DefaultFALSE, meaning put the extra textinthe put the textunderthe box. See IfTRUE, position the leaf nodes at the bottom of the the node numbers. DefaultFALSE. (In the current implementation someoverplotting may occur withnn=TRUE.)niDisplay the node indices, the row numbers of the nodes in the object sframe. of0don t writeyesandnoon the tree1(default) writeyesandnoat the top split2writeyesandnoat all splits. Seems to work best , (Theyesnoargument is ignored iftype=3or4. the othernnparameters to change the color etc. of theyesandnotext. change the actual text displayed.)branchControls the shape of the branch lines. Specify a value between0(V shapedbranches) and1(square shouldered branches).Default isif( ) 1 else . (the default), the vertical spacing of the nodes is uniform. IfFALSE,the nodes are spaced proportionally to the fit (more precisely, to the differencebetween a node s deviance and the sum of its two children s deviances).
6 Verysmall vertical spaces are automatically artificially expanded to make room forthe labels, seeminbranch. Note:uniform=FALSE withcex=NULL(the default)can sometimes cause very small , meaning the left side of a split is the path taken if the split con-dition is true. Withleft=FALSEthe split labels are changed so the right side IfTRUE, flip the tree IfTRUE, flip the tree vertically, so the root is at the number of significant digits in displayed numbers. , usegetOption("digits").If negative, use the standardformatfunction (with the absolute value ofdigits).Whendigitsis positive, the following details apply:Numbers printed without an exponent (and the numberof digits is actually only a suggestion, seeformatfor details). Numbers out thatrange are printed with an engineering exponent (a multiple of 3).varlenLength of variable names in text at the splits (and, for class responses, the classin the node label).
7 Default-8, meaning truncate to eight characters. Possiblevalues:0use full than 0callabbreviatewith the than 0truncate variable names to the shortest length where they are stillunique, but never truncate to shorter thanabs(varlen).faclenLength of factor level names in splits. Default3, meaningabbreviatetothree characters. Possible values are asvarlenabove, except that for back-compatibility special value1means represent the factorlevels with alphabetic characters (afor the first level,bfor the second, etc.).roundintNew in version (default) and all values of a predictorin the training data are integers, then splits for that predictor are rounded to6prpinteger. For example, displaynsiblings < 3instead ofnsiblings < the data used to build the model is no longer available, awarning will be advised if non-integer values are in fact possible fora predictor, even though all values in the training data for that predictor , meaning calculate the text size font sizes are discrete, thecexyou ask for may not be exactly the (possibly automatically calculated)cex.
8 Usingtweakis often easierthan defaulttweakis1, meaning no saytweak= make the text 20% font sizes are discrete, a small change to tweak may not actually changethe type size, or change it more than you in version IfTRUE, print splits on factors asfemaleinstead ofsex = female; the variable name and equals is example: printsurvivedordiedrather thansurvived = survivedorsurvived = only iftype= isTRUE meaning clip the right-hand split labels, , don t printvariable=.See (the default), make more space by shifting nodes horizontally wherespace is available. This often allows larger text. (This is the same sargument of the same name, except that here the default isTRUE.)ycompressIfTRUE(the default unlessuniform=FALSE), make more space by shifting labelsvertically where space is available. Actually, this only kicks in if the initialautomatically calculatedcexis less Useycompress=FALSEif you feelthe resulting display is too messy.
9 In the current implementation, the shiftingalgorithm works a little better (allowing larger text) withtype=1,2, white space around the tree, as a fraction of the graph width. Default0,meaning no extra space. To add say 10% space around the tree useMargin= (This is themarginargument The name was changed to preventpartial matching withmar, which can be passed in as a .. argument.)spaceHorizontal space to the box border on each side of the node label text, in char-acter widths. Default1. Use this (andyspace) for bigger boxes. Since thisaffects the size of the (possibly invisible) boxes, it also affects the graph layoutand hence also the automatic calculation horizontal gap between the (possibly invisible) boxes, in characterwidths. DefaultNULL, meaning automatically choose a suitable value (normally1, but if the graph is very crowded will be set to0, permitting boxes to touch toallow a biggercex).
10 See SetTRUEto interactively trim the tree with the mouse. See thepackage vignette (or just try it). invoked after each mouse click whensnip=TRUE. DefaultNULL, mean-ing no function. Otherwise your own function with the proto-typefunction(tree), wheretreeis the snipped tree. See the Package vignettefor an following control the node UseTRUEto print the automatically calculatedcex,xlim, andylim. Use integer values greater than 1 for more detailed of the boxes around the text. Default0, meaning use the background this argument is used, is for coloring the node boxes based on the fitted value. This is a vector ofcolors, for ("green","green2","green4"). Smallfitted values are displayed with colors at the start of the vector; large values withcolors at the end. Quantiles are used to partition the fitted special (default forprp) uses the background color(typically white).