Skip to contents

Display the nested structure of a "dichotomies" or "continuationDichotomies" object as a 2-D ASCII tree diagram showing how the response categories are split at each level of the nesting.

Usage

as.tree(x, ...)

# S3 method for class 'dichotomies'
as.tree(x, response = NULL, lobstr = FALSE, ...)

# S3 method for class 'continuationDichotomies'
as.tree(x, response = NULL, lobstr = FALSE, ...)

Arguments

x

A "dichotomies" or "continuationDichotomies" object.

...

additional arguments (currently unused).

response

Optional character string giving the name of the response variable, used as the root label of the tree. If NULL (default), the root is labeled "(response)".

lobstr

Logical. If FALSE (default), renders a 2-D ASCII tree with / and \ branch connectors, with each node centered above its two children. If TRUE, builds a nested list representation of the tree and renders it via tree, which must be installed.

Value

Invisibly returns x; called for its side effect of printing.

Details

The flat list of dichotomies is reconstructed into a binary tree by matching each dichotomy's domain (the union of its two sides) to the multi-level groups produced by earlier splits. Branch labels are taken from the named arguments to dichotomy when present, and are otherwise generated automatically as {level1, level2, ...}.

Examples

## Womenlf: named group on one branch
comparisons <- logits(work = dichotomy("not.work",
                                       working = c("parttime", "fulltime")),
                      full = dichotomy("parttime", "fulltime"))
as.tree(comparisons, response = "partic")
#>        partic
#>      /          \
#> not.work      working
#>               /      \
#>          parttime fulltime 

## GSS: continuation logits for ordered education levels
cont <- continuationLogits(c("<highschool", "highschool",
                             "college", "graduate"))
as.tree(cont, response = "degree")
#>              degree
#>       /                   \
#> <highschool {highschool, college, graduate}
#>                   /                  \
#>             highschool       {college, graduate}
#>                                  /          \
#>                              college     graduate 

## gators data: Food choice
# create dichotomies
gators.dichots <- logits(d1=dichotomy("Other", c("Fish", "Invertebrates")),
                         d2=dichotomy("Fish", "Invertebrates"))
as.tree(gators.dichots, response = "Food")
#>        Food
#>    /           \
#> Other {Fish, Invertebrates}
#>          /              \
#>       Fish         Invertebrates 
as.tree(gators.dichots, response = "Food", lobstr = TRUE)
#> <list>
#> └─Food: <list>
#>   ├─Other: "Other"
#>   └─{Fish, Invertebrates}: <list>
#>     ├─Fish: "Fish"
#>     └─Invertebrates: "Invertebrates"