80 Inferring a changepoint
In ?exr-changepoint-model, you developed a model for a changepoint analysis. The text of that problem is repeated below.
Consider the following twist on the experiment we have been considering where a retinal ganglion cell’s spiking is monitored under constant light. The retina is exposed to constant light, but at some time between the start and end of the experience, the impinging light intensity changes. That is, for \(0 \le t < s\), the retina is exposed to one light intensity, and for \(s \le t \le T\), it is exposed to another. The problem is that you do not know what \(s\) is, and you have to infer it. Your task is to construct a Bayesian model for this situation, complete with prior predictive checks.
This is a simple example of a decoding problem, in which a stimulus is inferred from neuronal signals.
For this data set, \(T = 60\) seconds.
Your task in this problem is to infer the neuron firing rates before and after the changepoint as well as the changepoint itself. Hint: It is often quite difficult to directly sample latent variables like a changepoint. If you can analytically marginalize out the changepoint \(s\), you may then be able to sample the other parameters and then after sampling compute the marginal distribution for \(s\). It may be useful to use the following integral for \(0 < t_1 < t_2 < \cdots < t_n < T\), where \(\theta(x)\) denotes a Heaviside step function.
\[\begin{align} \int_0^{T}\mathrm{d}s\,\prod_{i=1}^n\left[\beta_1 + (\beta_2 - \beta_1)\theta(t_i-s)\right]\,\mathrm{e}^{-(\beta_1-\beta_2)s} = \frac{\beta_2^n - \beta_1^n\,\mathrm{e}^{-(\beta_1 - \beta_2)T}}{\beta_1 - \beta_2} + \sum_{i=1}^n\beta_1^{i-1}\,\beta_2^{n-i}\,\mathrm{e}^{-(\beta_1 - \beta_2)t_i}. \end{align} \]