Defining a zero-sum constraint

Hello everyone, Stan newbie here!

I have a zero-sum identifiability constraint as following

43%20PM

parameter def is a normal distribution and it is a hyperparameter for the model. Is there anybody that can help me the way of thinking to code this in Stan? If some contexts are missing, I would like to give extra information. Thanks in advance!

There has been quite an extensive discussion on this semi-recently. Probably more than you need to know: Test: Soft vs Hard sum-to-zero constrain + choosing the right prior for soft constrain

TLDR: either use sum(x) ~ normal(0, <small_number> * <num_lements>) or the code in this answer in the aformentioned thread + the one below (which is in my experience slightly superior). For more details read the whole topic.

Hello Martin thank you for your response. I checked that post before opening this thread but seemed little bit advance regarding my issue.

I have two questions based on your answer.

is this the way of coding zero-sum or some sort of pseudo code?

Parameter def, that I have, has a mean ~ normal(0,10) and a variance ~half-cauchy(0,2.5). In this scenario, is sum(def) ~ normal(mean, <small_number> * <num_elements> * variance) definition reasonable.

ps: I am sorry if doesn’t make any sense. I am not a statistician and now I am trying to re-simulate one paper. It’s difficult to move from Matlab to R and Stan.

Sorry, not much time, just quick shots, hope that helps.

Replace the things in <> with some actual numbers and it is actual code (check the full discussion on the topic for details).

Having a sum-to-zero constraint on a vector of numbers with non-zero mean is IMHO problematic (the sum than has non-zero expected value but you constrain it to be zero) and I can’t think of a real use case that would require it (I might be wrong though).

1 Like

Thank you so much Martin for your help and your time!