kiriwhan
kiriwhan

Reputation: 41

decision trees with forced structure

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:

Thanks in advance, and help is much appreciated.

Upvotes: 4

Views: 2132

Answers (2)

Ross
Ross

Reputation: 113

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.

Upvotes: 1

jey1401
jey1401

Reputation: 371

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.

Upvotes: 0

Related Questions