@@ -111,41 +111,48 @@ print(rate.cate)
111
111
# We can use the `maq` package for this exercise. This package is more general
112
112
# and accepts CATE estimates from multiple treatment arms along with costs that
113
113
# denominate what we spend by assigning a unit a treatment. In this application
114
- # we can simply treat the number of units we are considering deploying as the cost.
114
+ # we can simply set cost to 1 and compute a Qini curve with fraction treated on
115
+ # the x-axis.
115
116
116
- # Form a doubly robust estimate of a CATE-based Qini curve (using eval.forest).
117
- num.units = nrow(X )
118
- qini = maq(tau.hat.test ,
119
- num.units ,
120
- get_scores(eval.forest ) * num.units ,
121
- R = 200 )
117
+ # Form a doubly robust estimate of the Qini curve, using R=200 bootstrap replications for std.errors.
118
+ cost = 1
119
+ qini = maq(tau.hat.test , cost , get_scores(eval.forest ), R = 200 )
122
120
123
121
# Form a baseline Qini curve that assigns treatment uniformly.
124
- qini.baseline = maq(tau.hat.test ,
125
- num.units ,
126
- get_scores(eval.forest ) * num.units ,
127
- R = 200 ,
122
+ qini.baseline = maq(tau.hat.test , cost , get_scores(eval.forest ), R = 200 ,
128
123
target.with.covariates = FALSE )
129
124
130
- # Plot the Qini curve along with 95% confidence lines.
131
- plot(qini , ylab = " PTSD cases prevented" , xlab = " Units held back from deployment" , xlim = c(0 , num.units ))
132
- plot(qini.baseline , add = TRUE , ci.args = NULL )
125
+ # Plot the Qini curve with 95% confidence intervals.
126
+ # This shows the expected gain from withholding units from deployments in order of predicted benefit.
127
+
128
+ # Suppose the application allows intervening on up to 2000 units.
129
+ # We use `maq_scale()` to rescale the Qini curve to this real-world deployment size.
130
+ max.deployment = 2000
131
+
132
+ # Plot the scaled Qini curve.
133
+ scale_maq(qini , max.deployment ) | >
134
+ plot(ylab = " PTSD cases prevented" ,
135
+ xlab = " Units held back from deployment" )
136
+
137
+ # Add a baseline curve on top.
138
+ scale_maq(qini.baseline , max.deployment ) | >
139
+ plot(add = TRUE , ci.args = NULL )
133
140
134
141
# Get estimates from the curve, at for example 500 deployed units.
135
- average_gain(qini , 500 )
142
+ average_gain(scale_maq( qini , max.deployment ) , 500 )
136
143
137
144
# Compare the benefit of targeting the 500 units predicted to benefit the most with the baseline.
138
- difference_gain(qini , qini.baseline , 500 )
139
-
145
+ difference_gain(scale_maq( qini , max.deployment ),
146
+ scale_maq( qini.baseline , max.deployment ), 500 )
140
147
141
148
# [The paper shows Qini curves embellished with ggplot. We could have retrieved
142
149
# the data underlying the curves and customized our plots further.
143
- # For more details we refer to https://github.com/ grf-labs/maq]
150
+ # For examples see https://grf-labs.github.io /maq/reference/plot.maq.html ]
144
151
145
152
146
153
# *** Describing the fit CATE function ****
147
154
148
- # Our `cate.forest` has given us some estimated function \tau(x ).
155
+ # Our `cate.forest` has given us some estimated function \hat tau().
149
156
# Let's have a closer look at how this function stratifies our sample in terms of "covariate" profiles.
150
157
# One way to do so is to look at histograms of our covariates by for example low / high CATE predictions.
151
158
0 commit comments