Type: Package
Title: Bayesian Inference in Regression Discontinuity Designs
Version: 0.1.0
Description: Implementation of the LoTTA (Local Trimmed Taylor Approximation) model described in "Bayesian Regression Discontinuity Design with Unknown Cutoff" by Kowalska, van de Wiel, van der Pas (2024) <doi:10.48550/arXiv.2406.11585>.
License: GPL-2 | GPL-3 [expanded from: GPL (≥ 2)]
Encoding: UTF-8
RoxygenNote: 7.3.2
Imports: stats, bayestestR, utils
Depends: R (≥ 4.4.0), runjags, ggplot2, ggpubr
NeedsCompilation: no
Packaged: 2025-07-07 15:29:27 UTC; juliakowalska
Author: Julia Kowalska ORCID iD [aut, cre, cph]
Maintainer: Julia Kowalska <j.m.kowalska@vu.nl>
Repository: CRAN
Date/Publication: 2025-07-11 12:20:02 UTC

Function that evaluates the binary outcome function in a domain x, given the coefficients

Description

Function that evaluates the binary outcome function in a domain x, given the coefficients

Usage

BIN_outcome_function_sample(coef_s, x, d_x, s_x)

Arguments

coef_s
  • list with the function coefficients

x
  • points at which the function is evaluated

d_x
  • shifting parameter that was used to normalize x

s_x
  • scaling parameter that was used to normalize x

Value

list with the values of the function


Function that splits the data into bins and computes the average in each bin

Description

Function that splits the data into bins and computes the average in each bin

Usage

Bin_data(y, x, c = NULL, binsize = 0.2)

Arguments

y
  • is the outcome data

x
  • is the score data

c
  • specifies the cutoff point, set to NULL if the binning of the data should be independent from c

binsize
  • length of the interval that is one bin

Value

list with elements y_bin: list of average values of y in each bin, x_bin: list of middle points for each bin


Function that evaluates the continuous outcome function in a domain x, given the coefficients

Description

Function that evaluates the continuous outcome function in a domain x, given the coefficients

Usage

CONT_outcome_function_sample(coef_s, x, d_x, s_x, mu_y, sd_y)

Arguments

coef_s
  • list with the function coefficients

x
  • points at which the function is evaluated

d_x
  • shifting parameter that was used to normalize x

s_x
  • scaling parameter that was used to normalize x

mu_y
  • shifting parameter that was used to normalize y

sd_y
  • scaling parameter that was used to normalize y

Value

list with the values of the function


function that samples initial values for fuzzy LoTTA model with a continuous prior and binary outcomes

Description

function that samples initial values for fuzzy LoTTA model with a continuous prior and binary outcomes

Usage

Initial_CONT_BIN(x, t, y, C_start, clb, cub, lb, ubr, ubl, s, jlb = 0.2)

Arguments

x
  • score data

t
  • treatment data

y
  • outcome data

C_start
  • posterior samples of cutoff location obtained through "cutoff_initial_CONT.txt"c

clb
  • left end of an interval on which the prior is supported

cub
  • right end of an interval on which the prior is supported

lb
  • minimum window size

ubr
  • maximum value of the window's right boundary point

ubl
  • minimum value of the window's left boundary point

s
  • seed

jlb
  • minimum jump size

Value

list with initial parameters values for LoTTA model with continuous score and binary outcomes, and .RNG.seed value


function that samples initial values for fuzzy LoTTA model with a ontinuous prior and continuous outcomes

Description

function that samples initial values for fuzzy LoTTA model with a ontinuous prior and continuous outcomes

Usage

Initial_CONT_CONT(x, t, y, C_start, clb, cub, lb, ubr, ubl, s, jlb = 0.2)

Arguments

x
  • score data

t
  • treatment data

y
  • outcome data

C_start
  • posterior samples of cutoff location obtained through "cutoff_initial_CONT.txt"

clb
  • left end of an interval on which the prior is supported

cub
  • right end of an interval on which the prior is supported

lb
  • minimum window size

ubr
  • maximum value of the window's right boundary point

ubl
  • minimum value of the window's left boundary point

s
  • seed

jlb
  • minimum jump size

Value

list with initial parameters values for LoTTA model with continuous score and continuous outcomes, and .RNG.seed value


function that samples initial values for LoTTA with a discerete prior and binary ourcomes

Description

function that samples initial values for LoTTA with a discerete prior and binary ourcomes

Usage

Initial_DIS_BIN(x, t, y, Ct_start, cstart, grid, lb, ubr, ubl, s, jlb = 0.2)

Arguments

x
  • score data

t
  • treatment data

y
  • outcome data

Ct_start
  • posterior samples of cutoff location (categorized by natural numbers) obtained through "cutoff_initial_DIS.txt"

cstart
  • the first point with a positive prior mass

grid
  • distance between two consecutive points with nonzero prior mass

lb
  • minimum window size (grid size in case of discrete score)

ubr
  • maximum value of the window's right boundary point

ubl
  • minimum value of the window's left boundary point

s
  • seed

jlb
  • minimum jump size

Value

list with initial parameters values for LoTTA model with discrete score and binary outcomes, and .RNG.seed value


function that samples initial values for fuzzy LoTTA model with a discrete prior and binary outcomes

Description

function that samples initial values for fuzzy LoTTA model with a discrete prior and binary outcomes

Usage

Initial_DIS_CONT(x, t, y, Ct_start, cstart, grid, lb, ubr, ubl, s, jlb = 0.2)

Arguments

x
  • score data

t
  • treatment data

y
  • outcome data

Ct_start
  • posterior samples of cutoff location (categorized by natural numbers) obtained through "cutoff_initial_dis.txt"c

cstart
  • the first point with a positive prior mass

grid
  • distance between two consecutive points with nonzero prior mass

lb
  • minimum window size (grid size in case of discrete score)

ubr
  • maximum value of the window's right boundary point

ubl
  • minimum value of the window's left boundary point

s
  • seed

jlb
  • minimum jump size

Value

list with initial parameters values for LoTTA model with discrete score and continuous outcomes, and .RNG.seed value


function that samples initial values for fuzzy LoTTA model with a known cutoff and binary outcomes

Description

function that samples initial values for fuzzy LoTTA model with a known cutoff and binary outcomes

Usage

Initial_FUZZy_BIN(x, t, y, c, lb, ubr, ubl, s, jlb = 0.2)

Arguments

x
  • score data

t
  • treatment data

y
  • outcome data

c
  • cutoff location

lb
  • minimum window size

ubr
  • maximum value of the window's right boundary point

ubl
  • minimum value of the window's left boundary point

s
  • seed

jlb
  • minimum jump size

Value

list with initial parameters values for fuzzy LoTTA model with a known cutoff and binary outcomes, and .RNG.seed value


function that samples initial values for fuzzy LoTTA model with a known cutoff and continuous outcomes

Description

function that samples initial values for fuzzy LoTTA model with a known cutoff and continuous outcomes

Usage

Initial_FUZZy_CONT(x, t, y, c, lb, ubr, ubl, s, jlb = 0.2)

Arguments

x
  • score data

t
  • treatment data

y
  • outcome data

c
  • cutoff value

lb
  • minimum window size

ubr
  • maximum value of the window's right boundary point

ubl
  • minimum value of the window's left boundary point

s
  • seed

jlb
  • minimum jump size

Value

list with initial parameters values for LoTTA model with continuous score and continuous outcomes, and .RNG.seed value


function that samples initial values for sharp LoTTA model with binary outcomes

Description

function that samples initial values for sharp LoTTA model with binary outcomes

Usage

Initial_SHARP_BIN(x, y, c, lb, ubr, ubl, s)

Arguments

x
  • score data

y
  • outcome data

c
  • cutoff location

lb
  • minimum window size

ubr
  • maximum value of the window's right boundary point

ubl
  • minimum value of the window's left boundary point

s
  • seed

Value

list with initial parameters values for sharp LoTTA model with binary outcomes, and .RNG.seed value


function that samples initial values for sharp LoTTA model with continuous outcomes

Description

function that samples initial values for sharp LoTTA model with continuous outcomes

Usage

Initial_SHARP_CONT(x, y, c, lb, ubr, ubl, s)

Arguments

x
  • score data

y
  • outcome data

c
  • cutoff location

lb
  • minimum window size

ubr
  • maximum value of the window's right boundary point

ubl
  • minimum value of the window's left boundary point

s
  • seed

Value

list with initial parameters values for sharp LoTTA model with continuous outcomes, and .RNG.seed value


function that samples initial values for the treatment model with a continuous prior

Description

function that samples initial values for the treatment model with a continuous prior

Usage

Initial_treatment_CONT(x, t, C_start, clb, cub, lb, ubr, ubl, s, jlb = 0.2)

Arguments

x
  • score data

t
  • treatment data

C_start
  • posterior samples of cutoff location obtained through "cutoff_initial_CONT.txt"

clb
  • left end of an interval on which the prior is supported

cub
  • right end of an interval on which the prior is supported

lb
  • minimum window size

ubr
  • maximum value of the window's right boundary point

ubl
  • minimum value of the window's left boundary point

s
  • seed

jlb
  • minimum jump size

Value

list with initial parameters values for LoTTA model with continuous score and .RNG.seed value


function that samples initial values for the treatment model with a discrete prior

Description

function that samples initial values for the treatment model with a discrete prior

Usage

Initial_treatment_DIS(x, t, Ct_start, cstart, grid, lb, ubr, ubl, s, jlb = 0.2)

Arguments

x
  • score data

t
  • treatment data

Ct_start
  • posterior samples of cutoff location (categorized by natural numbers) obtained through "cutoff_initial_dis.txt"c

cstart
  • the first point with a positive prior mass

grid
  • distance between two consecutive points with nonzero prior mass

lb
  • minimum window size (grid size in case of discrete score)

ubr
  • maximum value of the window's right boundary point

ubl
  • minimum value of the window's left boundary point

s
  • seed

jlb
  • minimum jump size

Value

list with initial parameters values for treatment model with discrete score and .RNG.seed value


function that samples initial values for the treatment model with a known cutoff

Description

function that samples initial values for the treatment model with a known cutoff

Usage

Initial_treatment_c(x, t, c, lb, ubr, ubl, s, jlb = 0.2)

Arguments

x
  • score data

t
  • treatment data

c
  • cutoff location

lb
  • minimum window size

ubr
  • maximum value of the window's right boundary point

ubl
  • minimum value of the window's left boundary point

s
  • seed

jlb
  • minimum jump size

Value

list with initial parameters values for LoTTA model with continuous score and .RNG.seed value


LoTTA_fuzzy_BIN

Description

Function that fits LoTTA model to the fuzzy RD data with binary outcomes 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_fuzzy_BIN(
  x,
  t,
  y,
  c_prior,
  jlb = 0.2,
  ci = 0.95,
  trimmed = NULL,
  outcome_prior = list(pr = 1e-04),
  n_min = 25,
  param = c("c", "j", "kl", "kr", "eff", "a0l", "a1l", "a2l", "a3l", "a0r", "a1r", "a2r",
    "a3r", "b1lt", "a1lt", "a2lt", "b2lt", "b1rt", "a1rt", "a2rt", "b2rt", "k1t", "k2t"),
  normalize = TRUE,
  n.chains = 4,
  burnin = 10000,
  sample = 1000,
  adapt = 500,
  inits = NULL,
  method = "parallel",
  seed = NULL,
  ...
)

Arguments

x
  • is the score data

t
  • is the treatment allocation data

y
  • is the binary outcome data

c_prior
  • specifies the cutoff prior in case of the unknown cutoff or the cutoff point if the cutoff is known. Takes as value a number if the cutoff is known or a list of values otherwise. For a continuous prior the list requires the following elements: clb - left end of the interval cub - right end of the interval in which the scaled and translated beta distribution is defined, alpha (optional) - shape parameter, default value = 1, beta (optional) - shape parameter, default value = 1. For a discrete prior the list requires the following elements: cstart - first point with positive prior mass, cend - last point with positive prior mass, grid - distance between the consecutive points in the support weights (optional) - vector of weights assigned to each point in the support, default is vector of 1's (uniform distribution)

jlb
  • minimum jump size

ci
  • specifies the probability level 1-alpha for the highest posterior density intervals; default is ci = 0.95

trimmed
  • takes as a value NULL or a vector of two values. It specifies potential trimming of the data. If set to NULL no trimming is applied to the data. If a list of two values is provided the data is trimmed to include data points with the score x in between those values; default is trimmed=NULL

outcome_prior
  • takes as a value a list with elements 'pr'. 'pr' specifies precision in the normal priors on the coefficients in the outcome function; default is list('pr'=0.0001)

n_min
  • specifies the minimum number of data points to which a cubic part of the outcome function is fit to ensure stability of the sampling procedure; default is n_min=25

param
  • takes as a value a vector with names of the parameters that are to be sampled; default is the list of all parameters

normalize
  • specifies if the data is to be normalized. The data is normalized as follows. If the prior is continuous: x_normalized=(x-d)/s, where d=(min(x)+max(x))*0.5 and s=max(x)-min(x). If the prior is discrete: x_normalized=x/s, where s=10^m, where m is chosen so that |max(abs(x))-1| is minimal. The priors inside the model are specified for the normalized data, in extreme cases not normalizing the data may lead to unreliable results; default is normalize=TRUE

n.chains
  • specifies the number of chains in the MCMC sampler; default is n.chains=4

burnin
  • specifies the number of burnin iterations without the adaptive iterations; default is burnin=5000

sample
  • specifies the number of samples per chain; default is samples=5000

adapt
  • specifies the number of adaptive iterations in the MCMC sampler; default is adapt=1000

inits
  • initial values for the sampler. By default the initial values are sampled inside the function. To run LoTTA with a method other than "parallel" inits must be set to NA or to a user defined value. If the user wants to provide its own values please refer to run.jags manual; default inits=NULL

method
  • set to default as 'parallel', which allows to sample the chains in parallel reducing computation time. To read more about possible method values type ?run.jags; default method='parallel'

seed
  • specifies the seed for replicability purposes; default is seed=NULL

...
  • other arguments of run.jags function. For more details type ?run.jags

Value

The function returns the list with the elements:

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_binary <- function(x) {
  y = x
  P = funB(x)
  for (j in 1:length(x)) {
    y[j] = sample(c(1, 0), 1, prob = c(P[j], 1 - P[j]))
  }
  return(y)
}

## Toy example - for the function check only! ##
N=100
x = sort(runif(N, -1, 1))
t = sample_prob55(x)
y = funB_sample_binary(x)
c_prior=0 # known cutoff c=0

# running LoTTA model on fuzzy RDD with binary outcomes;
out = LoTTA_fuzzy_BIN(x,t,y,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)
  y = funB_sample_binary(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 binary 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_BIN(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)

 

LoTTA_fuzzy_CONT

Description

Function that fits LoTTA model to the fuzzy RD data with continuous outcomes 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_fuzzy_CONT(
  x,
  t,
  y,
  c_prior,
  jlb = 0.2,
  ci = 0.95,
  trimmed = NULL,
  outcome_prior = list(pr = 1e-04, shape = 0.01, scale = 0.01),
  n_min = 25,
  param = c("c", "j", "kl", "kr", "eff", "a0l", "a1l", "a2l", "a3l", "a0r", "a1r", "a2r",
    "a3r", "b1lt", "a1lt", "a2lt", "b2lt", "b1rt", "a1rt", "a2rt", "b2rt", "k1t", "k2t",
    "tau1r", "tau2r", "tau1l", "tau2l"),
  normalize = TRUE,
  n.chains = 4,
  burnin = 10000,
  sample = 1000,
  adapt = 500,
  inits = NULL,
  method = "parallel",
  seed = NULL,
  ...
)

Arguments

x
  • is the score data

t
  • is the treatment allocation data

y
  • is the binary outcome data

c_prior
  • specifies the cutoff prior in case of the unknown cutoff or the cutoff point if the cutoff is known. Takes as value a number if the cutoff is known or a list of values otherwise. For a continuous prior the list requires the following elements: clb - left end of the interval cub - right end of the interval in which the scaled and translated beta distribution is defined, alpha (optional) - shape parameter, default value = 1, beta (optional) - shape parameter, default value = 1. For a discrete prior the list requires the following elements: cstart - first point with positive prior mass, cend - last point with positive prior mass, grid - distance between the consecutive points in the support weights (optional) - vector of weights assigned to each point in the support, default is vector of 1's (uniform distribution)

jlb
  • minimum jump size

ci
  • specifies the probability level 1-alpha for the highest posterior density intervals; default is ci = 0.95

trimmed
  • takes as a value NULL or a vector of two values. It specifies potential trimming of the data. If set to NULL no trimming is applied to the data. If a list of two values is provided the data is trimmed to include data points with the score x in between those values; default is trimmed=NULL

outcome_prior
  • takes as a value a list with elements 'pr' and 'shape', 'scale'. 'pr' specifies precision in the normal priors on the coefficients in the outcome function. 'shape' and 'scale' specify the shape and scale parameters in the gamma prior on the precision of the error terms; default is list('pr'= 0.0001,'shape'= 0.01,'scale'= 0.01)

n_min
  • specifies the minimum number of data points to which a cubic part of the outcome function is fit to ensure stability of the sampling procedure; default is n_min=25

param
  • takes as a value a vector with names of the parameters that are to be sampled; default is the list of all parameters

normalize
  • specifies if the data is to be normalized. The data is normalized as follows. If the prior is continuous: x_normalized=(x-d)/s, where d=(min(x)+max(x))*0.5 and s=max(x)-min(x), If the prior is discrete: x_normalized=x/s, where s=10^m, where m is chosen so that |max(abs(x))-1| is minimal. The outcome data is normalized as follows: y_normalized=(y-mu)/sd, where mu=mean(y) and sd=sd(y). The priors inside the model are specified for the normalized data, in extreme cases not normalizing the data may lead to unreliable results; default is normalize=TRUE

n.chains
  • specifies the number of chains in the MCMC sampler; default is n.chains=4

burnin
  • specifies the number of burnin iterations without the adaptive iterations; default is burnin=5000

sample
  • specifies the number of samples per chain; default is samples=5000

adapt
  • specifies the number of adaptive iterations in the MCMC sampler; default is adapt=1000

inits
  • initial values for the sampler. By default the initial values are sampled inside the function. To run LoTTA with a method other than "parallel" inits must be set to NA or to a user defined value. If the user wants to provide its own values please refer to run.jags manual; default inits=NULL

method
  • set to default as 'parallel', which allows to sample the chains in parallel reducing computation time. To read more about possible method values type ?run.jags; default method='parallel'

seed
  • specifies the seed for replicability purposes; default is seed=NULL

...
  • other arguments of run.jags function. For more details type ?run.jags

Value

The function returns the list with the elements:

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)
}

## Toy example - for the function check only! ##
N=100
x = sort(runif(N, -1, 1))
t = sample_prob55(x)
y = funB_sample(x)
c_prior=0 # known cutoff c=0

# running LoTTA model on fuzzy RDD with continuous outcomes;
out = LoTTA_fuzzy_CONT(x,t,y,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)
  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)
  # 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,nbins = 5)



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
  • output of one of the LoTTA functions (LoTTA_fuzzy_CONT, LoTTA_fuzzy_BIN) with all parameters sampled (the default option in those functions)

nbins
  • number of bins to aggregate the values of the posterior cutoff location

probs
  • list of two quantiles that limit the range of cutoff values displayed on the plots

x_lab
  • label of the x-axis

y_lab1
  • label of the y-axis of the bottom plot

y_lab2
  • label of the y-axis of the top plot

title
  • title of the plot

axis.text
  • can be any value that is accepted in the argument axis.text in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default is changes font to a serif one axis.text=element_text(family = "sans",size = 10)

text
  • can be any value that is accepted in the argument text in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default is changes font to a serif one text=element_text(family='serif')

plot.theme
  • ggplot2 plot theme (see https://ggplot2.tidyverse.org/reference/ggtheme.html) possibly with additional arguments, it takes the default value plot.theme=theme_classic(base_size = 14),

plot.title
  • can be any value that is accepted in the argument plot.title in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default it centers the plot title plot.title = element_text(hjust = 0.5)

...
  • other arguments of the theme function, refer to ggplot2 manual

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)



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).

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_CONT(
  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
  • output of one of the LoTTA functions (LoTTA_fuzzy_CONT, LoTTA_fuzzy_BIN) with all parameters sampled (the default option in those functions)

nbins
  • number of bins to aggregate the input data

probs
  • list of two quantiles that limit the range of cutoff values displayed on the plots

x_lab
  • label of the x-axis

y_lab1
  • label of the y-axis of the bottom plot

y_lab2
  • label of the y-axis of the top plot

title
  • title of the plot

axis.text
  • can be any value that is accepted in the argument axis.text in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default is changes font to a serif one axis.text=element_text(family = "sans",size = 10)

text
  • can be any value that is accepted in the argument text in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default is changes font to a serif one text=element_text(family='serif')

plot.theme
  • ggplot2 plot theme (see https://ggplot2.tidyverse.org/reference/ggtheme.html) possibly with additional arguments, it takes the default value plot.theme=theme_classic(base_size = 14),

plot.title
  • can be any value that is accepted in the argument plot.title in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default it centers the plot title plot.title = element_text(hjust = 0.5)

...
  • other arguments of the theme function, refer to ggplot2 manual

Value

ggplot2 object


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).

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_DIS(
  LoTTA_posterior,
  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
  • output of one of the LoTTA functions (LoTTA_fuzzy_CONT, LoTTA_fuzzy_BIN) with all parameters sampled (the default option in those functions)

probs
  • list of two quantiles that limit the range of cutoff values displayed on the plots

x_lab
  • label of the x-axis

y_lab1
  • label of the y-axis of the bottom plot

y_lab2
  • label of the y-axis of the top plot

title
  • title of the plot

axis.text
  • can be any value that is accepted in the argument axis.text in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default is changes font to a serif one axis.text=element_text(family = "sans",size = 10)

text
  • can be any value that is accepted in the argument text in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default is changes font to a serif one text=element_text(family='serif')

plot.theme
  • ggplot2 plot theme (see https://ggplot2.tidyverse.org/reference/ggtheme.html) possibly with additional arguments, it takes the default value plot.theme=theme_classic(base_size = 14),

plot.title
  • can be any value that is accepted in the argument plot.title in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default it centers the plot title plot.title = element_text(hjust = 0.5)

...
  • other arguments of the theme function, refer to ggplot2 manual

Value

ggplot2 object


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
  • output of one of the LoTTA functions (LoTTA_sharp_CONT, LoTTA_fuzzy_CONT, LoTTA_sharp_BIN, LoTTA_fuzzy_BIN) with all the parameters sampled (the default option in those functions)

nbins
  • number of bins to aggregate the input data

probs
  • list of three quantiles, the first and the last one define the quanatile-based credible interval, the middle value defines the quantile of the posterior function to plot; by default the quantiles correspond to the median posterior function and 95% credible interval probs=c(0.025,0.5,0.975)

n_eval
  • n_eval*range(x) is the number of points at which each posterior function is evaluated, the higher number means slower computing time and a smoother plot; default n_eval=200

col_line
  • the color of the line and the band

size_line
  • thickness of the line

alpha_interval
  • alpha value of the band, lower values correspond to a more transparent color

col_dots
  • color of the dots that correspond to the binned data

size_dots
  • size of the dots that correspond to the binned data

alpha_dots
  • transparency of the dots that correspond to the binned data, lower values correspond to a more transparent color

col_cutoff
  • color of the dotted line at the cutoff

title
  • title of the plot

subtitle
  • subtitle of the plot

y_lab
  • label of the y-axis

x_lab
  • label of the x-axis

plot.theme
  • ggplot2 plot theme (see https://ggplot2.tidyverse.org/reference/ggtheme.html) possibly with additional arguments, it takes the default value plot.theme=theme_classic(base_size = 14),

legend.position
  • position of the legend, refer to ggplot2 manual for the possible values; by default legend is not printed legend.position='none'

name_legend
  • title of the legend

labels_legend
  • the label of the plotted function in the legend

text
  • can be any value that is accepted in the argument text in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default is changes font to a serif one text=element_text(family='serif')

legend.text
  • can be any value that is accepted in the argument legend.text in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default is changes font size to the legend to 14 legend.text=element_text(size = 14)

plot.title
  • can be any value that is accepted in the argument plot.title in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default it centers the plot title plot.title = element_text(hjust = 0.5)

plot.subtitle
  • can be any value that is accepted in the argument plot.subtitle in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default it centers the plot subtitle plot.title = element_text(hjust = 0.5)

...
  • other arguments of the theme function, refer to ggplot2 manual

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)

Function that plots the median (or another quantile) of the LoTTA posterior treatment probability 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 proportion of treated is calculated in each bin. The proportions 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.

Description

Function that plots the median (or another quantile) of the LoTTA posterior treatment probability 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 proportion of treated is calculated in each bin. The proportions 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_treatment(
  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 = "Treatment probability 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 treatment prob. 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
  • output of one of the LoTTA functions (LoTTA_fuzzy_CONT, LoTTA_fuzzy_BIN, LoTTA_treatment) with all the parameters sampled (the default option in those functions)

nbins
  • number of bins to aggregate the input data

probs
  • list of three quantiles, the first and the last one define the quanatile-based credible interval, the middle value defines the quantile of the posterior function to plot; by default the quantiles correspond to the median posterior function and 95% credible interval probs=c(0.025,0.5,0.975)

n_eval
  • n_eval*range(x) is the number of points at which each posterior function is evaluated, the higher number means slower computing time and a smoother plot; default n_eval=200

col_line
  • the color of the line and the band

size_line
  • thickness of the line

alpha_interval
  • alpha value of the band, lower values correspond to a more transparent color

col_dots
  • color of the dots that correspond to the binned data

size_dots
  • size of the dots that correspond to the binned data

alpha_dots
  • transparency of the dots that correspond to the binned data, lower values correspond to a more transparent color

col_cutoff
  • color of the dotted line at the cutoff

title
  • title of the plot

subtitle
  • subtitle of the plot

y_lab
  • label of the y-axis

x_lab
  • label of the x-axis

plot.theme
  • ggplot2 plot theme (see https://ggplot2.tidyverse.org/reference/ggtheme.html) possibly with additional arguments, it takes the default value plot.theme=theme_classic(base_size = 14),

legend.position
  • position of the legend, refer to ggplot2 manual for the possible values; by default legend is not printed legend.position='none'

name_legend
  • title of the legend

labels_legend
  • the label of the plotted function in the legend

text
  • can be any value that is accepted in the argument text in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default is changes font to a serif one text=element_text(family='serif')

legend.text
  • can be any value that is accepted in the argument legend.text in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default is changes font size to the legend to 14 legend.text=element_text(size = 14)

plot.title
  • can be any value that is accepted in the argument plot.title in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default it centers the plot title plot.title = element_text(hjust = 0.5)

plot.subtitle
  • can be any value that is accepted in the argument plot.subtitle in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default it centers the plot subtitle plot.title = element_text(hjust = 0.5)

...
  • other arguments of the theme function, refer to ggplot2 manual

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)
}



## 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)
# plot posterior fit of the treatment probablity function
LoTTA_plot_treatment(out,nbins = 60)

## 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)



LoTTA_sharp_BIN

Description

Function that fits LoTTA model to the sharp RD data with binary outcomes. 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_sharp_BIN(
  x,
  y,
  c,
  ci = 0.95,
  trimmed = NULL,
  outcome_prior = list(pr = 1e-04),
  n_min = 25,
  param = c("eff", "a0l", "a1l", "a2l", "a3l", "a0r", "a1r", "a2r", "a3r", "kl", "kr"),
  normalize = TRUE,
  n.chains = 4,
  burnin = 5000,
  sample = 5000,
  adapt = 1000,
  inits = NULL,
  method = "parallel",
  seed = NULL,
  ...
)

Arguments

x
  • is the score data

y
  • is the binary outcome data

c
  • specifies the cutoff point

ci
  • specifies the probability level 1-alpha for the highest posterior density intervals; default is ci = 0.95

trimmed
  • takes as a value NULL or a vector of two values. It specifies potential trimming of the data. If set to NULL no trimming is applied to the data. If a list of two values is provided the data is trimmed to include data points with the score x in between those values; deafult is trimmed=NULL

outcome_prior
  • takes as a value a list with elements 'pr'. 'pr' specifies precision in the normal priors on the coefficients in the outcome function; default is list('pr'=0.0001)

n_min
  • specifies the minimum number of data points to which a cubic part of the outcome function is fit to ensure stability of the sampling procedure; default is n_min=25

param
  • takes as a value a vector with names of the parameters that are to be sampled; default is the list of all parameters

normalize
  • specifies if the data is to be normalized. The data is normalized as follows. x_normalized=(x-d)/s, where d=(min(x)+max(x))*0.5 and s=max(x)-min(x). The priors inside the model are specified for the normalized data, in extreme cases not normalizing the data may lead to unreliable results; default is normalize=TRUE

n.chains
  • specifies the number of chains in the MCMC sampler; default is n.chains=4

burnin
  • specifies the number of burnin iterations without the adaptive iterations; default is burnin=5000

sample
  • specifies the number of samples per chain; default is samples=5000

adapt
  • specifies the number of adaptive iterations in the MCMC sampler; default is adapt=1000

inits
  • initial values for the sampler. By default the initial values are sampled inside the function. To run LoTTA with a method other than "parallel" inits must be set to NA or to a user defined value. If the user wants to provide its own values please refer to run.jags manual; default inits=NULL

method
  • set to default as 'parallel', which allows to sample the chains in parallel reducing computation time. To read more about possible method values type ?run.jags; default method='parallel'

seed
  • specifies the seed for replicability purposes; default is seed=NULL

...
  • other arguments of run.jags function. For more details type ?run.jags

Value

The function returns the list with the elements:

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! ##
# data generation
N=100
x = sort(runif(N, -1, 1))
y = sample_prob55(x)
c = 0

# running LoTTA model on a sharp RDD with a binary outcome
out = LoTTA_sharp_BIN(x, y, c, burnin = 50, sample = 50, adapt = 10,n.chains=1
                      ,method = 'simple',inits = NA)

## Use case example ##

  # data generation
  N=1000 # try different dataset size
  x = sort(runif(N, -1, 1))
  y = sample_prob55(x)
  c = 0

  # running LoTTA function on sharp RDD with binary outcomes;
  # cutoff = 0, treatment effect = 0.55
  # remember to check convergence and adjust burnin, sample and adapt if needed
  out = LoTTA_sharp_BIN(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,nbins = 60)


LoTTA_sharp_CONT

Description

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.

Usage

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,
  ...
)

Arguments

x
  • is the score data

y
  • is the continuous outcome data

c
  • specifies the cutoff point

ci
  • specifies the probability level 1-alpha for the highest posterior density intervals; default is ci = 0.95

trimmed
  • takes as a value NULL or a vector of two values. It specifies potential trimming of the data. If set to NULL no trimming is applied to the data. If a list of two values is provided the data is trimmed to include data points with the score x in between those values; deafult is trimmed=NULL

outcome_prior
  • takes as a value a list with elements 'pr' and 'shape', 'scale'. 'pr' specifies precision in the normal priors on the coefficients in the outcome function. 'shape' and 'scale' specify the shape and scale parameters in the gamma prior on the precision of the error terms; default is list('pr'= 0.0001,'shape'= 0.01,'scale'= 0.01)

n_min
  • specifies the minimum number of data points to which a cubic part of the outcome function is fit to ensure stability of the sampling procedure; default is n_min=25

param
  • takes as a value a vector with names of the parameters that are to be sampled; default is the list of all parameters

normalize
  • specifies if the data is to be normalized. The data is normalized as follows. x_normalized=(x-d)/s, where d=(min(x)+max(x))*0.5 and s=max(x)-min(x). y_normalized=(y-mu)/sd, where mu=mean(y) and sd=sd(y). The priors inside the model are specified for the normalized data, in extreme cases not normalizing the data may lead to unreliable results; default is normalize=TRUE

n.chains
  • specifies the number of chains in the MCMC sampler; default is n.chains=4

burnin
  • specifies the number of burnin iterations without the adaptive iterations; default is burnin=5000

sample
  • specifies the number of samples per chain; default is samples=5000

adapt
  • specifies the number of adaptive iterations in the MCMC sampler; default is adapt=1000

inits
  • initial values for the sampler. By default the initial values are sampled inside the function. To run LoTTA with a method other than "parallel" inits must be set to NA or to a user defined value. If the user wants to provide its own values please refer to run.jags manual; default inits=NULL

method
  • set to default as 'parallel', which allows to sample the chains in parallel reducing computation time. To read more about possible method values type ?run.jags; default method='parallel'

seed
  • specifies the seed for replicability purposes; default is seed=NULL

...
  • other arguments of run.jags function. For more details type ?run.jags

Value

The function returns the list with the elements:

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 = 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)

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
  • is the score data

t
  • is the treatment allocation data

c_prior
  • specifies the cutoff prior in case of the unknown cutoff or the cutoff point if the cutoff is known. Takes as value a number if the cutoff is known or a list of values otherwise. For a continuous prior the list requires the following elements: clb - left end of the interval cub - right end of the interval in which the scaled and translated beta distribution is defined, alpha (optional) - shape parameter, default value = 1, beta (optional) - shape parameter, default value = 1. For a discrete prior the list requires the following elements: cstart - first point with positive prior mass, cend - last point with positive prior mass, grid - distance between the consecutive points in the support weights (optional) - vector of weights assigned to each point in the support, default is vector of 1's (uniform distribution)

jlb
  • minimum jump size

ci
  • specifies the probability level 1-alpha for the highest posterior density intervals; default is ci = 0.95

trimmed
  • takes as a value NULL or a vector of two values. It specifies potential trimming of the data. If set to NULL no trimming is applied to the data. If a list of two values is provided the data is trimmed to include data points with the score x in between those values; default is trimmed=NULL

n_min
  • specifies the minimum number of data points to which a cubic part of the outcome function is fit to ensure stability of the sampling procedure; default is n_min=25

param
  • takes as a value a vector with names of the parameters that are to be sampled; default is the list of all parameters

normalize
  • specifies if the data is to be normalized. The data is normalized as follows. If the prior is continuous: x_normalized=(x-d)/s, where d=(min(x)+max(x))*0.5 and s=max(x)-min(x), If the prior is discrete: x_normalized=x/s, where s=10^m, where m is chosen so that |max(abs(x))-1| is minimal. The outcome data is normalized as follows: y_normalized=(y-mu)/sd, where mu=mean(y) and sd=sd(y). The priors inside the model are specified for the normalized data, in extreme cases not normalizing the data may lead to unreliable results; default is normalize=TRUE

n.chains
  • specifies the number of chains in the MCMC sampler; default is n.chains=4

burnin
  • specifies the number of burnin iterations without the adaptive iterations; default is burnin=5000

sample
  • specifies the number of samples per chain; default is samples=5000

adapt
  • specifies the number of adaptive iterations in the MCMC sampler; default is adapt=1000

inits
  • initial values for the sampler. By default the initial values are sampled inside the function. To run LoTTA with a method other than "parallel" inits must be set to NA or to a user defined value. If the user wants to provide its own values please refer to run.jags manual; default inits=NULL

method
  • set to default as 'parallel', which allows to sample the chains in parallel reducing computation time. To read more about possible method values type ?run.jags; default method='parallel'

seed
  • specifies the seed for replicability purposes; default is seed=NULL

...
  • other arguments of run.jags function. For more details type ?run.jags

Value

The function returns the list with the elements:

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)



function that finds maximum widow size to searxh for a cutoff

Description

function that finds maximum widow size to searxh for a cutoff

Usage

bounds(x, ns = 25)

Arguments

x
  • score data

ns
  • minimum number of data points on each side of the cutoff to which cubic parts are fitted

Value

list with ubl - minimum value of the window's left boundary point, ubr - maximum value of the window's right boundary point


inverse logit function

Description

inverse logit function

Usage

invlogit(x)

Arguments

x
  • score data

Value

value of inverse logit function at x


logit function

Description

logit function

Usage

logit(x)

Arguments

x
  • score data

Value

value of logit function at x


normalize continuous score function

Description

normalize continuous score function

Usage

normalize_cont_x(x, trimmed = NULL, normalize = TRUE)

Arguments

x
  • score data

trimmed
  • NULL by default, provide vector of score values to trim the data

normalize
  • whether data is to be normalized

Value

list with x - normalized score, d - parameter used to shift the score


normalize continuous outcome function

Description

normalize continuous outcome function

Usage

normalize_cont_y(y, x, trimmed = NULL, normalize = TRUE)

Arguments

y
  • outcome data

x
  • score data

trimmed
  • NULL by default, provide vector of values to trim the data

normalize
  • whether data is to be normalized

Value

list with y - normalized outcome, mu - shift parameter, sd - scaling parameter


normalize discrete score function

Description

normalize discrete score function

Usage

normalize_dis_x(x, trimmed = NULL, normalize = TRUE)

Arguments

x

score data

trimmed
  • NULL by default, provide vector of values to trim the data

normalize
  • TRUE by default, whether data is to be normalized

Value

list with x - normalized score, s - parameter used to scale the score


function that searches for initial parameters of outcome function to initiate the sampler

Description

function that searches for initial parameters of outcome function to initiate the sampler

Usage

optimal_k(x, y, c, lb, ubr, ubl)

Arguments

x
  • score data

y
  • outcome data

c
  • cutoff

lb
  • minimum window size

ubr
  • maximum value of the window's right boundary point

ubl
  • minimum value of the window's left boundary point

Value


function that searches for initial parameters of binary outcome function to initiate the sampler

Description

function that searches for initial parameters of binary outcome function to initiate the sampler

Usage

optimal_k_bin(x, y, c, lb, ubr, ubl)

Arguments

x
  • score data

y
  • outcome data

c
  • cutoff

lb
  • minimum window size

ubr
  • maximum value of the window's right boundary point

ubl
  • minimum value of the window's left boundary point

Value


Function that plots the median (or another quantile) of the posterior function with binary outcome 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.

Description

Function that plots the median (or another quantile) of the posterior function with binary outcome 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.

Usage

plot_outcome_BIN(
  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
  • output of one of the LoTTA functions (LoTTA_sharp, LoTTA_fuzzy)

nbins
  • number of bins to aggregate the input data

probs
  • list of three quantiles, the first and the last one define the quanatile-based credible interval, the middle value defines the quantile of the posterior function to plot; by default the quantiles correspond to the median posterior function and 95% credible interval probs=c(0.025,0.5,0.975)

n_eval
  • n_eval*range(x) is the number of points at which each posterior function is evaluated, the higher number means slower computing time and a smoother plot; default n_eval=200

col_line
  • the color of the line and the band

size_line
  • thickness of the line

alpha_interval
  • alpha value of the band, lower values correspond to a more transparent color

col_dots
  • color of the dots that correspond to the binned data

size_dots
  • size of the dots that correspond to the binned data

alpha_dots
  • transparency of the dots that correspond to the binned data, lower values correspond to a more transparent color

col_cutoff
  • color of the dotted line at the cutoff

title
  • title of the plot

subtitle
  • subtitle of the plot

y_lab
  • label of the y-axis

x_lab
  • label of the x-axis

plot.theme
  • ggplot2 plot theme (see https://ggplot2.tidyverse.org/reference/ggtheme.html) possibly with additional arguments, it takes the default value plot.theme=theme_classic(base_size = 14),

legend.position
  • position of the legend, refer to ggplot2 manual for the possible values; by default legend is not printed legend.position='none'

name_legend
  • title of the legend

labels_legend
  • the label of the plotted function in the legend

text
  • can be any value that is accepted in the argument text in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default is changes font to a serif one text=element_text(family='serif')

legend.text
  • can be any value that is accepted in the argument legend.text in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default is changes font size to the legend to 14 legend.text=element_text(size = 14)

plot.title
  • can be any value that is accepted in the argument plot.title in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default it centers the plot title plot.title = element_text(hjust = 0.5)

plot.subtitle
  • can be any value that is accepted in the argument plot.subtitle in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default it centers the plot subtitle plot.title = element_text(hjust = 0.5)

...
  • other arguments of the theme function, refer to ggplot2 manual

Value

ggplot2 object


Function that plots the median (or another quantile) of the posterior function of a continous outcome 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.

Description

Function that plots the median (or another quantile) of the posterior function of a continous outcome 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.

Usage

plot_outcome_CONT(
  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
  • output of one of the LoTTA functions (LoTTA_sharp, LoTTA_fuzzy)

nbins
  • number of bins to aggregate the input data

probs
  • list of three quantiles, the first and the last one define the quanatile-based credible interval, the middle value defines the quantile of the posterior function to plot; by default the quantiles correspond to the median posterior function and 95% credible interval probs=c(0.025,0.5,0.975)

n_eval
  • n_eval*range(x) is the number of points at which each posterior function is evaluated, the higher number means slower computing time and a smoother plot; default n_eval=200

col_line
  • the color of the line and the band

size_line
  • thickness of the line

alpha_interval
  • alpha value of the band, lower values correspond to a more transparent color

col_dots
  • color of the dots that correspond to the binned data

size_dots
  • size of the dots that correspond to the binned data

alpha_dots
  • transparency of the dots that correspond to the binned data, lower values correspond to a more transparent color

col_cutoff
  • color of the dotted line at the cutoff

title
  • title of the plot

subtitle
  • subtitle of the plot

y_lab
  • label of the y-axis

x_lab
  • label of the x-axis

plot.theme
  • ggplot2 plot theme (see https://ggplot2.tidyverse.org/reference/ggtheme.html) possibly with additional arguments, it takes the default value plot.theme=theme_classic(base_size = 14),

legend.position
  • position of the legend, refer to ggplot2 manual for the possible values; by default legend is not printed legend.position='none'

name_legend
  • title of the legend

labels_legend
  • the label of the plotted function in the legend

text
  • can be any value that is accepted in the argument text in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default is changes font to a serif one text=element_text(family='serif')

legend.text
  • can be any value that is accepted in the argument legend.text in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default is changes font size to the legend to 14 legend.text=element_text(size = 14)

plot.title
  • can be any value that is accepted in the argument plot.title in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default it centers the plot title plot.title = element_text(hjust = 0.5)

plot.subtitle
  • can be any value that is accepted in the argument plot.subtitle in the theme function of ggplot2 package,refer to ggplot2 manual for the possible values; by default it centers the plot subtitle plot.title = element_text(hjust = 0.5)

...
  • other arguments of the theme function, refer to ggplot2 manual

Value

ggplot2 object


function that checks the type of a prior and whether it is correct

Description

function that checks the type of a prior and whether it is correct

Usage

read_prior(prior, minx, maxx, ubl, ubr, lb)

Arguments

prior
  • list with prior parameters or a cutoff value

minx
  • minimum value of the score

maxx
  • maximum value of the score

ubl
  • minimum value of the window's left boundary point

ubr
  • maximum value of the window's right boundary point

lb
  • minimum window size

Value

list with type of prior and prior parameters


Function that evaluates the treatment probability function in a domain x, given the coefficients

Description

Function that evaluates the treatment probability function in a domain x, given the coefficients

Usage

treatment_function_sample(coef_s, x, d_x, s_x)

Arguments

coef_s
  • list with the function coefficients

x
  • points at which the function is evaluated

d_x
  • shifting parameter that was used to normalize x

s_x
  • scaling parameter that was used to normalize x

Value

list with the values of the function


Binary outcomes for trimmed score

Description

Binary outcomes for trimmed score

Usage

trim_dis_y(y, x, trimmed = NULL)

Arguments

y
  • outcome data

x
  • score data

trimmed
  • NULL by default, provide vector of values to trim the data

Value

list with y - outcomes for trimmed score