data.type <- "Bernoulli"
data.link <- "Logistic"
# Simulate current data
set.seed(1)
p <- 3
n_total <- 100
y <- rbinom(n_total,size=1,prob=0.6)
# The first column of x is the treatment indicator.
x <- cbind(rbinom(n_total,size=1,prob=0.5),
matrix(rnorm(p*n_total),ncol=p,nrow=n_total))
# Simulate two historical datasets
# Note that x0 does not have the treatment indicator
historical <- list(list(y0=rbinom(n_total,size=1,prob=0.2),
x0=matrix(rnorm(p*n_total),ncol=p,nrow=n_total)),
list(y0=rbinom(n_total, size=1, prob=0.5),
x0=matrix(rnorm(p*n_total),ncol=p,nrow=n_total)))
# Please see function "normalizing.constant" for how to obtain a0.coefficients
# Here, suppose one-degree polynomial regression is chosen by the "normalizing.constant"
# function. The coefficients are obtained for the intercept, a0_1 and a0_2.
a0.coefficients <- c(1, 0.5, -1)
# Set parameters of the slice sampler
# The dimension is the number of columns of x plus 1 (intercept)
# plus the number of historical datasets
lower.limits <- c(rep(-100, 5), rep(0, 2))
upper.limits <- c(rep(100, 5), rep(1, 2))
slice.widths <- rep(0.1, 7)
nMC <- 500 # nMC should be larger in practice
nBI <- 100
result <- glm.random.a0(data.type=data.type, data.link=data.link, y=y, x=x,
historical=historical, a0.coefficients=a0.coefficients,
lower.limits=lower.limits, upper.limits=upper.limits,
slice.widths=slice.widths, nMC=nMC, nBI=nBI)
summary(result)
Run the code above in your browser using DataLab