LoTTA_plot_treatment {LoTTA} | R Documentation |
Function that plots the median (or another quantile) of the LoTTA posterior treatment probability function along with the quanatile-based credible interval. The function is plotted on top of the binned input data. To bin the data, the score data is divided into bins of fixed length, then the proportion of treated is calculated in each bin. The proportions are plotted against the average values of the score in the corresponding bins. The data is binned separately on each side of the cutoff, the cutoff is marked on the plot with a dotted line. In case of an unknown cutoff, the MAP estimate is used.
Description
Function that plots the median (or another quantile) of the LoTTA posterior treatment probability function along with the quanatile-based credible interval. The function is plotted on top of the binned input data. To bin the data, the score data is divided into bins of fixed length, then the proportion of treated is calculated in each bin. The proportions are plotted against the average values of the score in the corresponding bins. The data is binned separately on each side of the cutoff, the cutoff is marked on the plot with a dotted line. In case of an unknown cutoff, the MAP estimate is used.
Usage
LoTTA_plot_treatment(
LoTTA_posterior,
nbins = 100,
probs = c(0.025, 0.5, 0.975),
n_eval = 200,
col_line = "#E69F00",
size_line = 0.1,
alpha_interval = 0.35,
col_dots = "gray",
size_dots = 3,
alpha_dots = 0.6,
col_cutoff = "black",
title = "Treatment probability function",
subtitle = NULL,
y_lab = "",
x_lab = expression(paste(italic("x"), " - score")),
plot.theme = theme_classic(base_size = 14),
legend.position = "none",
name_legend = "Legend",
labels_legend = "median treatment prob. fun.",
text = element_text(family = "serif"),
legend.text = element_text(size = 14),
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5),
...
)
Arguments
LoTTA_posterior |
|
nbins |
|
probs |
|
n_eval |
|
col_line |
|
size_line |
|
alpha_interval |
|
col_dots |
|
size_dots |
|
alpha_dots |
|
col_cutoff |
|
title |
|
subtitle |
|
y_lab |
|
x_lab |
|
plot.theme |
|
legend.position |
|
name_legend |
|
labels_legend |
|
text |
|
legend.text |
|
plot.title |
|
plot.subtitle |
|
... |
|
Value
ggplot2 object
Examples
# functions to generate the data
ilogit <- function(x) {
return(1 / (1 + exp(-x)))
}
fun_prob55 <- function(x) {
P = rep(0, length(x))
P[x >= 0.] = ilogit((8.5 * x[x >= 0.] - 1.5)) / 10.5 + 0.65 - 0.0007072
P[x < 0.] = (x[x < 0.] + 1)^4 / 15 + 0.05
return(P)
}
sample_prob55 <- function(x) {
P = rep(0, length(x))
P[x >= 0.] = ilogit((8.5 * x[x >= 0.] - 1.5)) / 10.5 + 0.65 - 0.0007072
P[x < 0.] = (x[x < 0.] + 1)^4 / 15 + 0.05
t = rep(0, length(x))
for (j in 1:length(x)) {
t[j] = sample(c(1, 0), 1, prob = c(P[j], 1 - P[j]))
}
return(t)
}
## Toy example - for the function check only! ##
N=100
x = sort(runif(N, -1, 1))
t = sample_prob55(x)
c_prior=0 # known cutoff
# running LoTTA treatment-only model;
out = LoTTA_treatment(x,t,c_prior,burnin = 50, sample = 50, adapt = 10,n.chains=1
,method = 'simple',inits = NA)
# plot posterior fit of the treatment probablity function
LoTTA_plot_treatment(out,nbins = 60)
## Use case example ##
N=500
x = sort(runif(N, -1, 1))
t = sample_prob55(x)
# comment out to try different priors:
c_prior=list(clb=-0.25,cub=0.25) # uniform prior on the interval [-0.25,0.25]
# c_prior=list(cstart=-0.25,cend=0.25,grid=0.05) # uniform discrete prior
# on -0.25, -0.2, ..., 0.25
# c_prior=0 # known cutoff c=0
# running LoTTA treatment-only model;
# cutoff = 0, compliance rate = 0.55
# remember to check convergence and adjust burnin, sample and adapt if needed
out = LoTTA_treatment(x,t,c_prior,burnin = 10000,sample = 5000,adapt=1000)
# print effect estimate:
out$Effect_estimate
# print JAGS output to asses convergence (the output is for normalized data)
out$JAGS_output
# plot posterior fit of the treatment probablity function
LoTTA_plot_treatment(out,nbins = 60)