| fit_spm_jags | R Documentation |
Unified JAGS interface for the shared-parameter model (SPM) with MNAR dropout:
family="gaussian": Continuous outcome.
family="bernoulli": Binary outcome.
fit_spm_jags(
df,
family = c("gaussian", "bernoulli"),
prior_theta = NULL,
params_to_save = NULL,
n.chains = 3,
n.iter = 10000,
n.burnin = 5000,
n.thin = 2,
parallel = FALSE
)
df |
Long-format |
family |
Either |
prior_theta |
Optional prior for
If |
params_to_save |
Character vector of parameter names to monitor.
If |
n.chains, n.iter, n.burnin, n.thin |
MCMC settings passed to |
parallel |
Logical; whether to run chains in parallel (via |
Numeric vector of posterior draws of \theta.
# ---- Example 1: Continuous outcome with weak prior ----
set.seed(1000)
# 1) Generate longitudinal data with MNAR monotone dropout
t_vec <- seq(4, 48, 4)
gen <- generate_spm(
n = 80, t_vec = t_vec, family = "gaussian",
alpha0 = -4, alpha1 = 0.05, rho = 1, sigma_b = 1,
theta = -3.2, # total change at the last visit (= slope * max(t))
sigma_e = 1
)
df <- gen$dat # long-format data: id, time, R, Y
# 2) Define a weakly informative prior for theta (one Normal component with large variance)
prior <- RBesT::mixnorm(c(1, 0, 1000)) # weight=1, mean=0, sd=1000
# 3) Fit the SPM (MNAR) and obtain posterior draws of theta
# Full MCMC fitting takes longer than a brief example check.
draws_theta <- fit_spm_jags(
df = df, family = "gaussian",
prior_theta = prior,
params_to_save = c("theta","slope","alpha0","alpha1","rho","sigma_e","sigma_b"),
n.chains = 3, n.iter = 10000, n.burnin = 5000, n.thin = 2, parallel = FALSE
)
# Summarize posterior results
summary(draws_theta) # posterior mean, median, quantiles
mean(draws_theta) # posterior mean of theta
# ---- Example 2: Binary outcome (probit link) with weak prior ----
set.seed(1000)
# 1) Generate longitudinal binary data with MNAR monotone dropout
t_vec <- seq(4, 48, 4)
gen <- generate_spm(
n = 200,
t_vec = t_vec,
family = "bernoulli",
alpha0 = -4, # dropout logit-intercept
alpha1 = 0.05, # dropout logit-slope in time
rho = -1, # association between random effect and dropout
sigma_b = 1, # SD of random intercept b_i
theta = 0.4, # target marginal Pr(Y=1) at final visit
beta0 = -2 # outcome probit-intercept
)
df <- gen$dat # long-format data: id, time, R, Y
# 2) Define a weakly informative prior for theta:
# Beta(1,1) (Uniform on (0,1)) as a one-component mixture
prior <- RBesT::mixbeta(c(1, 1, 1)) # weight=1, a=1, b=1
# 3) Fit the SPM (MNAR) with probit link for the binary outcome
# and obtain posterior draws of theta (final-visit response rate)
# Full MCMC fitting takes longer than a brief example check.
draws_theta <- fit_spm_jags(
df = df,
family = "bernoulli",
prior_theta = prior,
params_to_save = c("theta","slope","beta0","alpha0","alpha1","rho","sigma_b"),
n.chains = 3,
n.iter = 5000,
n.burnin = 3000,
n.thin = 2,
parallel = FALSE
)
# 4) Summarize posterior results
summary(draws_theta) # posterior mean, median, quantiles of theta
mean(draws_theta) # posterior mean of theta
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.