Discrete Transformed Parameters


I’m trying to help a fellow physicist with a model and I think Stan could do the job. I don’t believe the details are required to discuss the modeling process, so I’ll keep it abstract. It has to do with quantum computing.

The group is trying to build a chain of 1s and 0s, but occasionally an error occurs, and we observe two identical consecutive numbers (i.e. two 1s or two 0s). The goal is to evaluate how many errors occur in this experimental setup, and what distribution the number of errors follows. On top of that, we need to account for measurement errors: . there is an (exactly known) chance of measuring a 1 where there is a 0 and vice-versa.

My intuition would be to use a multinomial distribution, where each event corresponds to a specific number of errors. The last event would be “more than N errors”. This produces discrete transformed parameters which then need to be transformed again because of measurement errors. But Stan doesn’t give me a straightforward way of dealing with discrete parameters.

I am contemplating two options:

  1. Write a new distribution for the multinomial + measurement error process – hmm, might be a lot of work to determine that analytically.
  2. Simulate data from the experiment data to “correct” for the measurement error and then fit the Stan model (which would be a simple multinomial) to the “corrected” data - which feels like a risky hack.

Maybe Stan isn’t the right tool for this problem? I think a Gibbs sampler might work, though I hear discrete parameters are tricky.

Thank you for your help!

I’m going to claim this is not hard and it will be much more reliable than your alternative.

Until you provide the model, it’s hard to help.

The answer is almost certainly going to be to marginalize the discrete parameters unless they make up a time series, in which case, the answer is going to be “good luck”. You can see an example of a discrete measurement error problem in the multinomial setting in the marginalizing discrete variables chapter of the manual.

I’m going to disagree with @sakrejda and say that writing a new distribution shouldn’t be necessary. Now if you can do the marginalization of the measurement error directly, that’s great. Sometimes you can do this by converting into a CDF. For instance, if you round to integers and observe a 5, then what you really have is the CDF between 4.5 and 5.5 in the likelihood—that marginalizes out the true value.

The new distribution we’re talking about here is multinomial + false positive/false negative… that’s only a few alternatives to marginalize out!