# 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)
Run the code above in your browser using DataLab