LoTTA_plot_outcome {LoTTA} | R Documentation |
LoTTA_plot_outcome
Description
Function that plots the median (or another quantile) of the LoTTA posterior outcome 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 average outcome in each bin is calculated. The average outcomes 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_outcome(
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 = "Outcome 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 outcome 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)))
}
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)
}
## Toy example - for the function check only! ##
# data generation
N=100
set.seed(1234)
x = sort(runif(N, -1, 1))
y = funB_sample(x)
c = 0
# running LoTTA function on sharp RDD with continuous outcomes;
out = LoTTA_sharp_CONT(x, y, c,normalize=FALSE, burnin = 100, sample = 100, adapt = 100,
n.chains=1, seed = NULL,method = 'simple',inits = NA)
# plot the outcome
LoTTA_plot_outcome(out,n_eval = 100)
## Use case example ##
# data generation
N=500 # try different dataset size
x = sort(runif(N, -1, 1))
y = funB_sample(x)
c = 0
# plot the data
plot(x,y)
# running LoTTA function on sharp RDD with continuous outcomes;
# cutoff = 0, treatment effect = -0.2
# remember to check convergence and adjust burnin, sample and adapt if needed
out = LoTTA_sharp_CONT(x, y, c, burnin = 10000, sample = 5000, adapt = 1000,n.chains=4)
# print effect estimate:
out$Effect_estimate
# print JAGS output to asses convergence (the output is for normalized data)
out$JAGS_output
# plot posterior fit
LoTTA_plot_outcome(out)