# Estimating Propensity Score via Regression Trees (in R Using rpart)

I am trying to estimate propensity scores in R. By this I mean that I am trying to estimate probability that an individual selects into treatment, where the selection into treatment is a binary variable. Typically people use logit or probit to estimate these. I was thinking of using regression trees.

Is it okay to use rpart "anova" method to estimate propensities? I think I cannot use classification tree because that gives a binary outcome whereas I want the continuous propensity score function i.e. how does probability of treatment changes as the continuous explanatory variables changes.

I am using the following command where x and z are continuous explanatory variables and d is a binary treatment variable and all 3 are observed for each individual and I want to estimate P(D=1|X,Z).

  cart = rpart(d~x+z, data=data, method="anova")

data[,pz_c:=predict(cart, type = "vector")]


where the first command estimates the propensity and the second adds the predicted propensities to the data set for each individual.

I originally posted this on stackoverflow and was told to post thee question here instead.

You can use logistic regression itself, since your target variable is binary.

While predicting, use type = "prob" This will provide the propensities which is basically just the probability of being a 1 or 0.

• So is using cart "anova" correct? Should I instead use "class" method and predict propensities using type="prob"? – user52932 May 31 '18 at 14:30
• Use method = 'class' with type = 'prob'. As per your question, target variable is not continuous. – aathiraks Jun 1 '18 at 6:00