LoTTA_treatment {LoTTA} | R Documentation |
LoTTA_treatment
Description
Function that fits LoTTA treatment model to the fuzzy RD treatment data with an either known or unknown/suspected cutoff. It supports two types of priors on the cutoff location: a scaled beta distribution of the form beta(alpha,beta)(cub-clb)+clb and a discrete distribution with the support of the form cstart+grid i for i=0,...,(cend-cstart)/grid. The score does NOT have to be normalized beforehand. We recommend NOT to transform the data before imputing it into the function, except for initial trimming of the score 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.
Usage
LoTTA_treatment(
x,
t,
c_prior,
jlb = 0.2,
ci = 0.95,
trimmed = NULL,
n_min = 25,
param = c("c", "j", "b1lt", "a1lt", "a2lt", "b2lt", "b1rt", "a1rt", "a2rt", "b2rt",
"k1t", "k2t"),
normalize = TRUE,
n.chains = 4,
burnin = 5000,
sample = 1000,
adapt = 500,
inits = NULL,
method = "parallel",
seed = NULL,
...
)
Arguments
x |
|
t |
|
c_prior |
|
jlb |
|
ci |
|
trimmed |
|
n_min |
|
param |
|
normalize |
|
n.chains |
|
burnin |
|
sample |
|
adapt |
|
inits |
|
method |
|
seed |
|
... |
|
Value
The function returns the list with the elements:
Effect_estimate: contains a list with MAP estimate and HDI of the cutoff location (if unknown) and the discontinuity size in the treatment probability function (compliance rate at c) 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 cutoff location (c) if unknown, and compliance rate (j);
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 priors' parameters ;
Inits contains the list of initial values and .RNG.seed value
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)
## 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)