/********************************************************************** * grouped univariate normal model * Peng Zeng @ Auburn University * 2025-09-15 * * data: * counts of observations in K bins * (-inf, c[1]), (c[1], c[2]), ..., (c[k-2], c[k-1]), (c[K-1], inf) * model: * y ~ normal(mu, sigma) * prior: * f(mu, sigma) ~ 1/sigma **********************************************************************/ data { int K; // number of bins int counts[K]; // counts in each bin vector[K-1] cuts; // sorted cutpoints: c[1] < ... < c[K-1] } parameters { real mu; // mean of the normal distribution real sigma; // std.dev of the normal distribution } transformed parameters { vector[K] logp; // log of bin probabilities (up to a constant) logp[1] = normal_lcdf(cuts[1] | mu, sigma); // first bin: (-inf, c1) for(i in 2:(K-1)) { logp[i] = log_diff_exp( normal_lcdf(cuts[i] | mu, sigma), normal_lcdf(cuts[i-1] | mu, sigma) ); } // middle bin: (c[i-1], c[i]) logp[K] = normal_lccdf(cuts[K-1] | mu, sigma); // last bin: (c[K-1], inf) } model { counts ~ multinomial_logit(logp); // noninformative prior: f(mu, sigma) ~ 1/sigma target += -log(sigma); } /********************************************************************** * THE END **********************************************************************/