Last data update: 2014.03.03

R: rpart to graphNEL Converter
rpart2gNELR Documentation

rpart to graphNEL Converter

Description

Creates an object of class graphNEL from one of class rpart.

Usage

rpart2gNEL(tr, remap=function(x) x, nsep="\n")

Arguments

tr

instance of rpart class from rpart package.

remap

function that maps node names in tree to node names in graph.

nsep

token that separates node name and vote tally in the rendering.

Details

Not explicitly used in the book, but the basis for a certain graph illustrating application of rpart. The newer coin/party packages have more interesting rendering approaches based on graphviz.

grabSplitV is a utility function for acquiring the variable names, remapAff will remap affymetrix probe names to gene symbols for use in the remap parameter.

Value

a graphNEL-class instance with nodes constructed to convey information on the data tree fit

Author(s)

Vince Carey <stvjc@channing.harvard.edu>

See Also

rpart, graphNEL-class

Examples

library(rpart)
example(rpart)
ff = rpart2gNEL(fit2)
ff
nodes(ff)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(RbcBook1)
Loading required package: Biobase
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
    get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
    match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
    rbind, rownames, sapply, setdiff, sort, table, tapply, union,
    unique, unsplit

Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.

Loading required package: graph
Loading required package: rpart
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/RbcBook1/rpart2gNEL.Rd_%03d_medium.png", width=480, height=480)
> ### Name: rpart2gNEL
> ### Title: rpart to graphNEL Converter
> ### Aliases: rpart2gNEL rpart2gNEL grabSplitV remapAff
> ### Keywords: models
> 
> ### ** Examples
> 
> library(rpart)
> example(rpart)

rpart> fit <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis)

rpart> fit2 <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis,
rpart+               parms = list(prior = c(.65,.35), split = "information"))

rpart> fit3 <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis,
rpart+               control = rpart.control(cp = 0.05))

rpart> par(mfrow = c(1,2), xpd = NA) # otherwise on some devices the text is clipped

rpart> plot(fit)

rpart> text(fit, use.n = TRUE)

rpart> plot(fit2)

rpart> text(fit2, use.n = TRUE)
> ff = rpart2gNEL(fit2)
> ff
A graphNEL graph with directed edges
Number of Nodes = 5 
Number of Edges = 4 
> nodes(ff)
[1] "absent\n(64:17)"  "absent\n(44:2)"   "present\n(20:15)"
[4] "absent\n(9:1)"    "present\n(11:14)"
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>