3

I'm inspecting tests/usersplits.R in rpart, trying to get my head around how to pass data to the split function.

I'm trying to instantiate a number of goodness measures which compare treatment vs control within splits.

A simple example is difference-in-difference estimate of a candidate split,

(Y_t - Y_c)_L - (Y_t - Y_c)_R (difference between treatment and control for the left minus difference between treatment and control for the right)

I need to know whether each Y value is a treatment Y or a control. the documentation in usersplits.R says that Y is provided in sort order of X, so I'm not sure how to pass a vector indicating treatment vs control that will split Y appropriately.

rpart.poisson takes a two column matrix as an input, and I've been trying to mimic that, but there's no documentation in rpart.poisson (I can't figure out where it creates the 'vector of goodness')

rcs
  • 67,191
  • 22
  • 172
  • 153
justin cress
  • 1,745
  • 5
  • 24
  • 35
  • There has to a be a better solution, but could you use the `wt` (case weights) argument to pass the case/control information to these functions? (Assumes, of course, you don't need that argument already) – joran Jan 30 '12 at 23:17
  • maybe. I haven't thought about it. I'll look in to it. It might work for the immediate problem, but i wouldn't want to 'overload' the parameter long term. (in case wt needs to fill its intended purpose) – justin cress Jan 31 '12 at 00:01
  • I haven't tested this, but if passing a two column matrix for y is kosher, you should be able to just do that, and do the calculations on the first column using the values in the second column as indices indicating case/control. – joran Jan 31 '12 at 00:14
  • i'm not sure passing two columns is kosher, i just know rpart.poisson accepts a y that is n x 2, so I'm trying to figure out how that works. – justin cress Jan 31 '12 at 00:34
  • You can read this material: https://cran.r-project.org/web/packages/rpart/vignettes/usercode.pdf. It shows how to define you own splitting function to use in the `rpart` package. – igorkf Sep 09 '20 at 00:17

0 Answers0