Pedantic-mode missing prior false alarm
Open
Nobody has claimed this yet.
- Dominant language
- OCaml
- Stars
- 160
- Forks
- 59
- Avg merge
- 21h 45m
- Merged PRs (30d)
- 26
Description
With the following model, pedantic-mode syntax check is telling me "Warning: The parameter z has no priors." when it does indeed have one; possibly the new array syntax is foiling the check?
data{
// k: num predictors
int<lower=1> k ;
// w: predictor array
matrix[k,k] uw ;
// n: number of subj
int<lower=1> n ;
// m: num entries in the observation vectors
int<lower=k> m ;
// num_total: number of observations per subject/condition
array[m] int<lower=1> num_total ;
// num_successes: sum of observations per subject/condition
array[m] int<lower=0,upper=num_total> num_successes ;
// row: for each observation, row index in w (see TD below)
array[m] int<lower=1,upper=n*k> row ;
}
transformed data{
// num_r: number of correlations implied by k
int num_r = (k * (k - 1)) %/% 2 ;
// compute observed intercept
real obs_intercept = logit(mean(to_vector(num_successes)./to_vector(num_total))) ;
// w: unique predictions repeated for each subject
array[k] matrix[n,k] w ;
for(i_k in 1:k){
w[i_k] = rep_matrix(uw[i_k],n);
}
}
parameters{
// chol_corr: population-level correlations (on cholesky factor scale) amongst within-subject predictors
cholesky_factor_corr[k] chol_corr ;
//for parameters below, trailing underscore denotes that they need to be un-scaled in generated quantities
// mu: mean (across subj) for each coefficient
row_vector[k] mu_ ;
// sigma: sd (across subj) for each coefficient
vector<lower=0>[k] sigma ;
// z: by-subject coefficients
array[n] row_vector[k] z ;
}
model{
////
// Priors
////
// relatively flat prior on correlations
chol_corr ~ lkj_corr_cholesky(2) ;
// normal(0,1) priors on all sds
sigma ~ std_normal() ;
// normal(0,1) priors on all means
mu_ ~ std_normal() ;
// mid-level multivariate structure
z ~ multi_normal_cholesky(
append_col(
mu_[1] + obs_intercept
, mu_[2:k]
)
, diag_pre_multiply(sigma, chol_corr)
) ;
//convert z from array of row-vectors to matrix
// (hopefully replaceable by `rows_dot_product(to_matrix(z),...) soon,
// see: https://github.com/stan-dev/cmdstan/issues/1015 )
matrix[n,k] z_mat ;
for(i_n in 1:n){
z_mat[i_n] = z[i_n] ;
}
// Loop over subj and conditions to compute unique entries in design matrix
matrix[n,k] z_dot_w ;
for(i_k in 1:k){
z_dot_w[,i_k] = rows_dot_product(z_mat, w[i_k]) ;
}
// Likelihood
num_successes ~ binomial(
num_total
, inv_logit(to_vector(z_dot_w))[row]
) ;
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied Stan model in pedantic mode, focusing on the array declaration for z and its multi_normal_cholesky prior. Then trace the pedantic prior-detection path in stanc3; done means the model no longer reports that z has no prior, with coverage for this array-syntax case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ocaml
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100