Hi,
I am trying to use a custom shaped prior for the treatment effect (risk difference) using an rgeneric latent effect. I'm able to create a prior with the following code, but am unsure of the syntax to fix this to a treatment indicator (0/1) coefficient. Would you able to help with this? Thanks so much!
rgeneric.pearsonIV <- function(
cmd = c("graph", "Q", "mu", "initial", "log.norm.const", "log.prior", "quit"),
theta = NULL,
m = 2, nu = -0.4,
location = 0.01, scale = 0.08
) {
interpret.theta <- function() list(value = as.numeric(theta))
graph <- function() Matrix::Diagonal(1)
Q <- function() Matrix::Diagonal(1, x = 1e6)
mu <- function() numeric(0)
log.norm.const <- function() numeric(0)
initial <- function() rep(0, 1)
quit <- function() invisible()
log.prior <- function() {
if (is.null(theta) ||
is.na(theta[1])) return(-Inf)
logd <- PearsonDS::dpearsonIV(
x = as.numeric(theta),
m = m, nu = nu, location = location, scale = scale,
log = TRUE
)
as.numeric(logd)
}
cmd <- match.arg(cmd)
val <- switch(cmd,
graph = graph(),
Q = Q(),
mu = mu(),
initial = initial(),
log.norm.const = log.norm.const(),
log.prior = log.prior(),
quit = quit())
return(val)
}
model_obj <- inla.rgeneric.define(
model=rgeneric.pearsonIV
)
# Run model with empty data
df_prior <- data.frame(y = NA, idx = 1)
result_prior <- inla(
y ~ f(idx, model = model_obj),
data = df_prior,
family = "gaussian",
control.family = list(hyper = list(prec = list(initial = log(1), fixed = T))), # Keeps precision constant
control.compute = list(config=T)
)
summary(result_prior)