/********************************************************************** * grouped normal model or interval-censored normal model **********************************************************************/ data { int K; // number of bins int counts[K]; // counts in each bin vector[K-1] cuts; // sorted cutpoints: c1 < ... < 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) // first bin: (-inf, c1) logp[1] = normal_lcdf(cuts[1] | mu, sigma); // middle bin: (c[i-1], c[i]) for(i in 2:(K-1)) { logp[i] = log_diff_exp( normal_lcdf(cuts[i] | mu, sigma), normal_lcdf(cuts[i-1] | mu, sigma) ); } // last bin: (c[K-1], inf) logp[K] = normal_lccdf(cuts[K-1] | mu, sigma); } model { counts ~ multinomial_logit(logp); // noninformative prior: (mu, sigma) ~ 1/sigma target += -log(sigma); } /********************************************************************** * THE END **********************************************************************/