View source: R/functions_main.R
LoTTA_sharp_CONT | R Documentation |
Function that fits LoTTA model to the sharp RD data with continuous outcomes. The data does NOT have to be normalized beforehand. We recommend NOT to transform the data before imputing it into the function, except for initial trimming which should be done beforehand. The further trimming for the sensitivity analysis can be done through the function, which ensures that the data is normalized before the trimming.
LoTTA_sharp_CONT(
x,
y,
c,
ci = 0.95,
trimmed = NULL,
outcome_prior = list(pr = 1e-04, shape = 0.01, scale = 0.01),
n_min = 25,
param = c("eff", "a0l", "a1l", "a2l", "a3l", "a0r", "a1r", "a2r", "a3r", "tau1r",
"tau2r", "tau1l", "tau2l", "kl", "kr"),
normalize = TRUE,
n.chains = 4,
burnin = 10000,
sample = 5000,
adapt = 1000,
inits = NULL,
method = "parallel",
seed = NULL,
...
)
x |
|
y |
|
c |
|
ci |
|
trimmed |
|
outcome_prior |
|
n_min |
|
param |
|
normalize |
|
n.chains |
|
burnin |
|
sample |
|
adapt |
|
inits |
|
method |
|
seed |
|
... |
|
The function returns the list with the elements:
Effect_estimate: contains a list with MAP estimate and HDI of the treatment effect on the original, unnormalized scale;
JAGS_output: contains output of the run.jags function for the normalized data if normalize=TRUE, based on this output mixing of the chains can be assessed;
Samples: contains posterior samples of the treatment effect (eff);
Normalized_data: contains a list of the normalized data (if normalized=TRUE) and the parameters used to normalize the data (see arg normalize);
Priors: contains a list of the outcome prior parameters ;
Inits contains the list of initial values and .RNG.seed value
# 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 = 50, sample = 50, adapt = 10,
n.chains=1, seed = NULL,method = 'simple',inits = NA)
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.