LoTTA_plot_effect {LoTTA} | R Documentation |
LoTTA_plot_effect
Description
Function that visualizes the impact of the cutoff location on the treatment effect estimate. It plots too figures. The bottom figure depicts the posterior density of the cutoff location. The top figure depicts the box plot of the treatment effect given the cutoff point. If the prior on the cutoff location was discrete each box corresponds to a distinct cutoff point. If the prior was continuous each box correspond to an interval of cutoff values (the number of intervals can be changed through nbins).
Usage
LoTTA_plot_effect(
LoTTA_posterior,
nbins = 10,
probs = c(0.025, 0.975),
x_lab = "Cutoff location",
y_lab1 = "Treatment effect",
y_lab2 = "Density of cutoff location",
title = "Cutoff location vs. Treatment effect",
axis.text = element_text(family = "sans", size = 10),
text = element_text(family = "serif"),
plot.theme = theme_classic(base_size = 14),
plot.title = element_text(hjust = 0.5),
...
)
Arguments
LoTTA_posterior |
|
nbins |
|
probs |
|
x_lab |
|
y_lab1 |
|
y_lab2 |
|
title |
|
axis.text |
|
text |
|
plot.theme |
|
plot.title |
|
... |
|
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)
}
funB <- function(x) {
y = x
x2 = x[x >= 0]
x1 = x[x < 0]
y[x < 0] = 1 / (1 + exp(-2 * x1)) - 0.5 + 0.4
y[x >= 0] = (log(x2 * 2 + 1) - 0.15 * x2^2) * 0.6 - 0.20 + 0.4
return(y)
}
funB_sample <- function(x) {
y = funB(x)+ rnorm(length(x), 0, 0.1)
return(y)
}
## Use case example ##
N=500
x = sort(runif(N, -1, 1))
t = sample_prob55(x)
y = funB_sample(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 model on fuzzy RDD with continuous outcomes and unknown cutoff;
# cutoff = 0, compliance rate = 0.55, treatment effect = -0.3636364
# remember to check convergence and adjust burnin, sample and adapt if needed
out = LoTTA_fuzzy_CONT(x,t,y,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 outcome function
LoTTA_plot_outcome(out,nbins = 60)
# plot posterior fit of the treatment probablity function
LoTTA_plot_treatment(out,nbins = 60)
# plot dependence of the treatment effect on the cutoff location
LoTTA_plot_effect(out)