Package uplift by Guelman (https://github.com/cran/uplift).
Simple plot reproduces uplift
package’s qini(...)
plot.
library(uplifteval)
set.seed(123)
alpha <- 0.1
n <- 1000
W <- rbinom(n, 1, 0.5)
Y <- W
p1 <- Y + alpha*rnorm(n)
plot_uplift_guelman(p1, W, Y, groups=10)
## [1] 1.0 100.9 200.8 300.7 400.6 500.5 600.4 700.3 800.2 900.1
## [11] 1000.0
## $Qini
## [1] 0.2476978
##
## $inc.gains
## [1] 0.2028398 0.4056795 0.6085193 0.8113590 1.0000000 1.0000000 1.0000000
## [8] 1.0000000 1.0000000 1.0000000
##
## $random.inc.gains
## [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
Now work with a slightly more realistic toy model.
library(grf)
rl <- function(x){
round(1/(1+exp(-x)))
}
n = 2000; p = 10
X = matrix(rnorm(n*p), n, p)
W = rbinom(n, 1, 0.2)
Y = rl(rl(X[,1]) * W - rl(X[,3]) * W + rnorm(n))
tau.forest = causal_forest(X, Y, W)
tau.hat = predict(tau.forest, X)
plot_uplift_guelman(tau.hat$predictions, W, Y)
## [1] 1.0 200.9 400.8 600.7 800.6 1000.5 1200.4 1400.3 1600.2 1800.1
## [11] 2000.0
## $Qini
## [1] 0.08695195
##
## $inc.gains
## [1] 0.07994898 0.09809889 0.10284188 0.10722604 0.12324585
## [6] 0.11527672 0.09911338 0.07809615 0.04094821 -0.01453885
##
## $random.inc.gains
## [1] -0.001453885 -0.002907769 -0.004361654 -0.005815539 -0.007269424
## [6] -0.008723308 -0.010177193 -0.011631078 -0.013084963 -0.014538847
The uplift
package splits into quantiles, but can have issues finding splits when distributions are highly concentrated.
library(tweedie)
#
# Case: plot_uplift_guelman fails to find quantiles
#
# Generate equal prediction distributions
n <- 1000
W <- rbinom(n, 1, 0.5)
Y <- rbinom(n, 1, 0.5)
p1 <- rtweedie(n, xi=1.4, mu=1, phi=1)
hist(p1,100)
## [1] 1.0 100.9 200.8 300.7 400.6 500.5 600.4 700.3 893.5
## Warning in performance(p1, p0, Y, W, direction = direction, groups):
## uplift: due to ties in uplift predictions, the number of groups is less
## than 10
## $Qini
## [1] 0.0008526142
##
## $inc.gains
## [1] 6.570513e-03 1.858974e-02 1.266026e-02 -2.884615e-03 -7.692308e-03
## [6] 7.401487e-18 5.448718e-03 6.570513e-03
##
## $random.inc.gains
## [1] 0.0008213141 0.0016426282 0.0024639423 0.0032852564 0.0041065705
## [6] 0.0049278846 0.0057491987 0.0065705128