Deductive only, centered
datlist = c(dat[dat$reason == "dedu", c("hi", "fa")],
nsubj = sum(dat$reason == "dedu")
)
s <- "
data {
int<lower=1> nsubj;
array[nsubj] int<lower=0, upper=4> hi;
array[nsubj] int<lower=0, upper=4> fa;
}
parameters {
vector[2] mu; // group sensitivity and bias
vector<lower=0>[2] sigma;
vector[nsubj] d; // by-subject sensitivity
vector[nsubj] c; // by-subject bias
}
model {
mu ~ normal([0.5, 0], [0.8, 0.7]);
sigma ~ normal(0, 5);
d ~ normal(mu[1], sigma[1]);
c ~ normal(mu[2], sigma[2]);
hi ~ binomial(4, Phi( d/2 - c));
fa ~ binomial(4, Phi(-d/2 - c));
}
"
m <- stan(model_code = s, data = datlist)
## Warning: There were 5 divergent transitions after warmup. See
## https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
## to find out why this is a problem and how to eliminate them.
## Warning: Examine the pairs() plot to diagnose sampling problems
## Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
## Running the chains for more iterations may help. See
## https://mc-stan.org/misc/warnings.html#bulk-ess
## Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
## Running the chains for more iterations may help. See
## https://mc-stan.org/misc/warnings.html#tail-ess
print(m, pars = c("mu", "sigma"), probs = c(.025, .975))
## Inference for Stan model: anon_model.
## 4 chains, each with iter=2000; warmup=1000; thin=1;
## post-warmup draws per chain=1000, total post-warmup draws=4000.
##
## mean se_mean sd 2.5% 97.5% n_eff Rhat
## mu[1] 2.55 0.01 0.40 1.78 3.34 1999 1.00
## mu[2] -0.26 0.00 0.16 -0.58 0.05 2256 1.00
## sigma[1] 2.13 0.03 0.55 1.20 3.37 453 1.01
## sigma[2] 0.66 0.01 0.22 0.22 1.10 230 1.02
##
## Samples were drawn using NUTS(diag_e) at Fri Nov 6 17:03:15 2026.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at
## convergence, Rhat=1).
pairs(m, pars = c("sigma[2]", paste0("c[", 1:5, "]")), log = TRUE, gap = 0)
## Warning in par(usr): Argument 1 bezeichnet keinen grafikpararmeter
## Warning in par(usr): Argument 1 bezeichnet keinen grafikpararmeter
## Warning in par(usr): Argument 1 bezeichnet keinen grafikpararmeter
## Warning in par(usr): Argument 1 bezeichnet keinen grafikpararmeter
## Warning in par(usr): Argument 1 bezeichnet keinen grafikpararmeter
## Warning in par(usr): Argument 1 bezeichnet keinen grafikpararmeter

Deductive only, noncentered
s <- "
data {
int<lower=1> nsubj;
array[nsubj] int<lower=0, upper=4> hi;
array[nsubj] int<lower=0, upper=4> fa;
}
parameters {
vector[2] mu;
vector<lower=0>[2] sigma;
matrix[nsubj, 2] z;
}
transformed parameters {
vector[nsubj] d = mu[1] + sigma[1] * z[, 1];
vector[nsubj] c = mu[2] + sigma[2] * z[, 2];
}
model {
mu ~ normal([0.5, 0], [0.8, 0.7]);
sigma ~ normal(0, 5);
to_vector(z) ~ std_normal();
hi ~ binomial(4, Phi( d/2 - c));
fa ~ binomial(4, Phi(-d/2 - c));
}
"
m <- stan(model_code = s, data = datlist)
print(m, pars = c("mu", "sigma"), probs = c(.025, .975))
## Inference for Stan model: anon_model.
## 4 chains, each with iter=2000; warmup=1000; thin=1;
## post-warmup draws per chain=1000, total post-warmup draws=4000.
##
## mean se_mean sd 2.5% 97.5% n_eff Rhat
## mu[1] 2.52 0.01 0.38 1.82 3.31 2614 1.00
## mu[2] -0.26 0.00 0.16 -0.57 0.05 3115 1.00
## sigma[1] 2.06 0.01 0.52 1.22 3.26 1368 1.01
## sigma[2] 0.64 0.01 0.21 0.27 1.08 1306 1.01
##
## Samples were drawn using NUTS(diag_e) at Fri Nov 6 17:04:19 2026.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at
## convergence, Rhat=1).
pairs(m, pars = c("sigma[2]", paste0("c[", 1:5, "]")), log = TRUE, gap = 0)
## Warning in par(usr): Argument 1 bezeichnet keinen grafikpararmeter
## Warning in par(usr): Argument 1 bezeichnet keinen grafikpararmeter
## Warning in par(usr): Argument 1 bezeichnet keinen grafikpararmeter
## Warning in par(usr): Argument 1 bezeichnet keinen grafikpararmeter
## Warning in par(usr): Argument 1 bezeichnet keinen grafikpararmeter
## Warning in par(usr): Argument 1 bezeichnet keinen grafikpararmeter
