recursive_tree: decision tree in a recursive way

Description Usage Arguments Value Examples

View source: R/recursive_tree.R

Description

decision tree in a recursive way

Usage

1
2
3
recursive_tree(data = data, Y = "Y", modele = NULL, kill = NULL,
  index = NULL, print = TRUE, plot = TRUE, main = NULL, sub = NULL,
  lang = c("en", "fr"), all = FALSE, digits = getOption("digits") - 3)

Arguments

data

the dataset including the response

Y

the name of the response

modele

(optional) vector of names of covariates allowed in the tree

kill

vector of the names to kill (variables won't be used in the tree)

index

to give a number to the plot

print

boolean to print the tree parameters

plot

boolean to plot the tree

main

the main title if plot=TRUE

sub

the subtitle (if NULL it is automatically added)

lang

the language for the automatic subtitle in the plot

all

Logical. If TRUE, all nodes are labeled, otherwise just terminal nodes.

digits

number of digits for legend of the leaves

Value

returns the tree as an "rpart" object and the modele as a vector of the names of the covariates the tree could have used (to give as an input of the function).

modele

vector of the names of the covariates the tree could have used

tree

the regression tree as an "rpart" object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
   ## Not run: 
   data<-mtcars
   require(CorReg)
main="Regression tree of cars consumption (in mpg)"
  mytree=recursive_tree(data = data,Y ="mpg" ,main=main)
   #want to try without cylinder and disp
  mytree2=recursive_tree(data = data,Y ="mpg" ,kill=c("cyl","disp"),modele=mytree$modele,main=main)
  
    
## End(Not run)

Example output

                                                                                                                    
                                                                                                                    
          CCCCCCCCCCCCC                                         RRRRRRRRRRRRRRRRR                                         
        CCC::::::::::::C                                        R::::::::::::::::R                                          
       CC:::::::::::::::C                                       R::::::RRRRRR:::::R                                         
      C:::::CCCCCCCC::::C                                       RR:::::R     R:::::R                                        
      C:::::C       CCCCCC   ooooooooooo      rrrrr   rrrrrrrrr   R::::R     R:::::R     eeeeeeeeeeee       ggggggggg   ggggg
      C:::::C               oo:::::::::::oo   r::::rrr:::::::::r  R::::R     R:::::R   ee::::::::::::ee    g:::::::::ggg::::g
      C:::::C              o:::::::::::::::o  r:::::::::::::::::r R::::RRRRRR:::::R   e::::::eeeee:::::ee g:::::::::::::::::g
      C:::::C              o:::::ooooo:::::or r::::::rrrrr::::::r R:::::::::::::RR   e::::::e     e:::::eg::::::ggggg::::::gg
      C:::::C              o::::o     o::::o  r:::::r     r:::::r R::::RRRRRR:::::R  e:::::::eeeee::::::eg:::::g     g:::::g 
      C:::::C              o::::o     o::::o  r:::::r     rrrrrrr R::::R     R:::::R e:::::::::::::::::e g:::::g     g:::::g 
      C:::::C              o::::o     o::::o  r:::::r             R::::R     R:::::R e::::::eeeeeeeeeee  g:::::g     g:::::g 
      C:::::C       CCCCCC o::::o     o::::o  r:::::r             R::::R     R:::::R e:::::::e           g::::::g    g:::::g 
      C:::::CCCCCCCC::::C  o:::::ooooo:::::o  r:::::r           RR:::::R     R:::::R e::::::::e          g:::::::ggggg:::::g 
       CC:::::::::::::::C  o:::::::::::::::o  r:::::r           R::::::R     R:::::R  e::::::::eeeeeeee   g::::::::::::::::g 
        CCC::::::::::::C   oo:::::::::::oo    r:::::r           R::::::R     R:::::R   ee:::::::::::::e    gg::::::::::::::g 
          CCCCCCCCCCCCC      ooooooooooo      rrrrrrr           RRRRRRRR     RRRRRRR     eeeeeeeeeeeeee      gggggggg::::::g 
                                                                                                                     g:::::g 
                                                                                                         gggggg      g:::::g 
                                                                                                         g:::::gg   gg:::::g 
                                                                                                         g::::::ggg:::::::g 
                                                                                                          gg:::::::::::::g  
                                                                                                             ggg::::::ggg    
                                                                                                                gggggg       
          
 The Concept, the Method, the Power
n= 32 

node), split, n, deviance, yval
      * denotes terminal node

1) root 32 1126.04700 20.09062  
  2) cyl>=5 21  198.47240 16.64762  
    4) hp>=192.5 7   28.82857 13.41429 *
    5) hp< 192.5 14   59.87214 18.26429 *
  3) cyl< 5 11  203.38550 26.66364 *
n= 32 

node), split, n, deviance, yval
      * denotes terminal node

1) root 32 1126.04700 20.09062  
  2) wt>=2.3925 25  320.44640 17.58800  
    4) hp>=177.5 10   48.53600 14.28000 *
    5) hp< 177.5 15   89.52933 19.79333 *
  3) wt< 2.3925 7   89.81429 29.02857 *

CorReg documentation built on Sept. 6, 2019, 3 a.m.