1

I am using the lmtree function from the partykit package and I am looking for a function similar to the path.rpart function, ie, a function which gives in a list the splits on the path from the root to the selected node.

It would like something similar to this :

 set.seed(1)
 library(rpart)
 x=runif(100);z=runif(100);y=jitter(ifelse(z>.5,2*x,3*x+2),amount=.1);
 rp=rpart(x~y)
 path.rpart(rp,5)

 #node number: 5 
 #root
 #y< 0.8785
 #y>=0.4081

with lmtree :

 library(partykit)
 tr=lmtree(x~y|z)
 #and here I need a function similar to path.rpart

I checked the node_party and get_paths functions but it is not what I need. Does any one have suggestions for extracting this info from the lmtree object ? Many thanks for your help.

user3507085
  • 700
  • 5
  • 17
  • 1
    Its easier to help you if you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and the code you used to build your model. Describe what the expected result is for that input so possible solutions can be tested and verified. – MrFlick Jan 19 '18 at 20:25
  • Too vague to be answered because you haven't explained clearly what you want. – InfiniteFlash Jan 19 '18 at 20:25
  • @MrFlick and InfiniteFlashChess You right I edited my question – user3507085 Jan 19 '18 at 21:34
  • use `set.seed()` with your example so we can get the same sample data values. Right now when I run your code there is no node 10 so I get an error. – MrFlick Jan 19 '18 at 21:39
  • Done, thank you for your help – user3507085 Jan 19 '18 at 21:44

1 Answers1

3

Models of class lmtree inherit from party just like the output from ctree(). Hence, the same approaches that are discussed here on SO for ctree() output can also be applied to lmtree() output. Namely, you can use the (still unexported) .list.rules.party() function:

partykit:::.list.rules.party(tr)
##                        2                        3 
## "z <= 0.495593577856198"  "z > 0.495593577856198" 

For further adaptations see: also:

Achim Zeileis
  • 15,710
  • 1
  • 39
  • 49