# Posterior distribution from piecewise likelihood

Consider a hierarchical Bayesian model for analysing data from an inhomogeneous Poisson process that we observe in discrete time. Let $$Y_i, i = 1,...,n$$, be the number of events occurring in the time interval $$[i−1,i]$$ and assume that

$$P(Y_i=y_i | \lambda,\theta,k) = \begin{cases} \frac{\lambda^{y_i}}{y_i!}e^{-\lambda} & \text{for } i ≤ k \\ \frac{\theta^{y_i}}{y_i!}e^{-\theta} & \text{for } i > k \end{cases}$$

where $$k$$ is an integer value. In other words, the intensity of the process is $$\lambda$$ before time k and $$\theta$$ after time k. Derive the posterior density of the unknown parameters given the observed data f(θ, λ, k|y1, . . . , yn) $$f(\theta,\lambda,k|y_1,...,y_n)$$.

The proposed solution:

The posterior density is: $$f(\theta,\lambda,k|y_1,...,y_n)\propto f(\lambda)f(\theta)f(k)f(y_i,...,y_n|\theta,\lambda,k)$$

= $$f(\lambda)f(\theta)f(k)\prod_{i=1}^{k}\frac{\lambda^{y_i}}{y_i!}e^{-\lambda}\prod_{i=k+1}^{n}\frac{\theta^{y_i}}{y_i!}e^{-\theta}$$

On the last line of the solution: Where do the two iterated products ($$\prod_{i=1}^{k}...\prod_{i=k+1}^{n}...$$) come from? In my intuition, the posterior $$f(y_i,...,y_n|\theta,\lambda,k)$$ should be a product of n factors, each being a y-distribution i.e. $$P(Y_i=y_i | \lambda,\theta,k)$$. Why does it suffice to include k factors from the first distribution and n-k factors from the second? I understand that Bayes's rule is involved here, but I can't seem to get the steps right.

Nevermind, I figured it out. I was thinking of each Y_i as one event that may occur at different times. It should be thought of as the number of events happening for one time interval $$i$$.

The two iterated products are just a decomposition of the overall product over the entire sample. That is, you have $$\prod_{i=1}^{n} ... = \prod_{i=1}^{k}... \times \prod_{i=k+1}^{n}...$$. Remember that the product symbol $$Pi$$ denotes a product over a set of terms, so it can be split into parts in the same way as any multiplication of more than two terms.

Now, rather than jumping straight to the posterior density, it is much better to first derive and simplify your likelihood function. Simplifying this function will make your posterior distribution look a lot simple. In this case, using the product decomposition over the two partial samples gives you the likelihood function:

\begin{equation} \begin{aligned} L_\mathbf{y}(\lambda, \theta, k) &= \prod_{i=1}^n P(Y_i=y_i| \lambda, \theta, k) \\[6pt] &= \Bigg( \prod_{i=1}^k P(Y_i=y_i| \lambda, \theta, k) \Bigg) \Bigg( \prod_{i=k+1}^n P(Y_i=y_i| \lambda, \theta, k) \Bigg) \\[6pt] &= \Bigg( \prod_{i=1}^k \frac{\lambda^{y_i}}{y_i!} \exp(-\lambda) \Bigg) \Bigg( \prod_{i=k+1}^n \frac{\theta^{y_i}}{y_i!} \exp(-\theta) \Bigg) \\[6pt] &= \exp(- k \lambda- (n-k) \theta) \Bigg( \prod_{i=1}^k \frac{\lambda^{y_i}}{y_i!} \Bigg) \Bigg( \prod_{i=k+1}^n \frac{\theta^{y_i}}{y_i!} \Bigg) \\[6pt] &\propto \exp(- k \lambda- (n-k) \theta) \Bigg( \prod_{i=1}^k \lambda^{y_i} \Bigg) \Bigg( \prod_{i=k+1}^n \theta^{y_i} \Bigg) \\[6pt] &= \exp(- k \lambda- (n-k) \theta) \lambda^{k \cdot \bar{y}_1} \theta^{(n-k) \cdot \bar{y}_2}, \\[6pt] \end{aligned} \end{equation}

where the partial sample means are:

$$\bar{y}_1 \equiv \frac{1}{k} \sum_{i=1}^k y_i \quad \quad \quad \quad \quad \bar{y}_2 \equiv \frac{1}{n-k} \sum_{i=k+1}^n y_i.$$

The corresponding log-likelihood function is:

$$\ell(\lambda, \theta, k) = - k \lambda- (n-k) \theta + k \cdot \bar{y}_1 \ln(\lambda) + (n-k) \cdot \bar{y}_2 \ln(\theta).$$

This gives you a nice simple form for your likelihood function and log-likelihood function, which should simplify the rest of your work.