4

I have been using decision trees (CART) in R using the rpart package to look at the relationship between SST (predictor variables) and climate (predictand variable).

I would like to "force" the tree into a particular structure - i.e. split on predictor variable 1, then on variable 2.

I've been using R for a while so I thought I'd be able to look at the code behind the rpart function and modify it to search for 'best splits' in a particular predictor variable first. However the rpart function calls C routines and not having any experience with C I get lost here...

I could write a function from scratch but would like to avoid it if possible! So my questions are:

  • Is there another decision tree technique (implemented in R preferably) in which you can force the structure of the tree?
  • If not - is there some way I could convert the C code to R?
  • Any other ideas?

Thanks in advance, and help is much appreciated.

blahdiblah
  • 33,069
  • 21
  • 98
  • 152
kiriwhan
  • 41
  • 3

2 Answers2

1

When your data indicates a tree with a known structure, present that structure to R using either a newick or nexus file format. Then you can read in the structure using either read.tree or read.nexus from Package Phylo.

Ross
  • 111
  • 1
  • 2
0

Maybe you should look at the method formal parameter of rpart

In the documentation :

... ‘method’ can be a list of functions named ‘init’, ‘split’ and ‘eval’. Examples are given in the file ‘tests/usersplits.R’ in the sources.

jey1401
  • 361
  • 2
  • 8