I've been trying to implement and extend some results from the papers "Always Valid Inference" and "Peeking at A/B Tests". The authors provide a closed form expression of the "mixture" likelihood ratio for a two-sided alternative hypothesis (i.e., where $\Theta$ can be any real number).
I'm interested in developing a closed form expression for the mixture likelihood ratio for one-sided alternatives (i.e., where $\Theta$ can only be positive or negative).
The authors did not provide a derivation, so here's my attempt
Solving the integral
- Assume data from cohort $A$ and cohort $B$ arrive in pairs $Z_n = (A_n, B_n)$
- $h(\theta) = \text{Normal}(0, \tau^2)$
- $f(X_i|\mu=\theta) = \text{Normal}(\theta, \sigma^2)$
- $f(X_i|\mu=\theta_0) = \text{Normal}(\theta_0, \sigma^2)$
$$\Lambda_T = \int_{\theta \in \Theta} h(\theta) \prod_{m=1}^T \frac{f(Z_m|\mu=\theta)}{f(Z_m|\mu=\theta_0)}d\theta $$
$$ =\int_{\theta \in \Theta} \frac{1}{\sqrt{2\pi\tau^2}}e^{\frac{-1}{2}\big(\frac{\theta - 0}{\tau}\big)^2} \prod_{m=1}^T \frac{\frac{1}{\sqrt{2\pi\sigma^2}} e^{\frac{-1}{2}\big(\frac{Z_m - \theta}{\sigma}\big)^2}}{\frac{1}{\sqrt{2\pi\sigma^2}} e^{\frac{-1}{2}\big(\frac{Z_m - \theta_0}{\sigma}\big)^2}} d\theta $$
$$ = \frac{1}{\sqrt{2\pi\tau^2}} \int_{\theta \in \Theta} \prod_{m=1}^T \Big[ \frac{e^{\frac{-1}{2}\big(\frac{Z_m - \theta}{\sigma}\big)^2}}{ e^{\frac{-1}{2}\big(\frac{Z_m - \theta_0}{\sigma}\big)^2}}\Big] e^{\frac{-1}{2}\big(\frac{\theta - 0}{\tau}\big)^2}d\theta $$
$$ = \frac{1}{\sqrt{2\pi\tau^2}} \int_{\theta \in \Theta} \prod_{m=1}^T \Big[ \exp \Big( \frac{-1}{2}\big((\frac{Z_m - \theta}{\sigma})^2 - (\frac{Z_m - \theta_0}{\sigma})^2\big)\Big) \Big] \exp \Big( \frac{-1}{2}\big(\frac{\theta - 0}{\tau}\big)^2 \Big)d\theta $$
$$ = \frac{1}{\sqrt{2\pi\tau^2}} \int_{\theta \in \Theta} \exp \Big[ \sum_{m=1}^T \Big( \frac{-1}{2}\big((\frac{Z_m - \theta}{\sigma})^2 - (\frac{Z_m - \theta_0}{\sigma})^2\big) \Big) + \frac{-1}{2}\big(\frac{\theta - 0}{\tau}\big)^2 \Big]d\theta $$
$$ = \frac{1}{\sqrt{2\pi\tau^2}} \int_{\theta \in \Theta} \exp \Big[ \frac{-1}{2} \big[\sum_{m=1}^T \Big(\big((\frac{Z_m - \theta}{\sigma})^2 - (\frac{Z_m - \theta_0}{\sigma})^2\big) \Big) + \big(\frac{\theta - 0}{\tau}\big)^2 \big]\Big]d\theta $$
$$ = \frac{1}{\sqrt{2\pi\tau^2}} \int_{\theta \in \Theta} \exp \Big[ \frac{-1}{2} \big[ \sum_{m=1}^T \Big(\frac{Z_m^2 -2Z_m\theta + \theta^2}{\sigma^2} - \frac{Z_m^2 -2Z_m\theta_0 + \theta_0^2}{\sigma^2}\big) \Big) + \big(\frac{\theta - 0}{\tau}\big)^2 \big] \Big]d\theta $$
$$ = \frac{1}{\sqrt{2\pi\tau^2}} \int_{\theta \in \Theta} \exp \Big[ \frac{-1}{2} \big[ \big(\frac{\sum_{m=1}^T Z_m^2}{\sigma^2} + \frac{-2\theta \sum_{m=1}^T Z_m + T\theta^2}{\sigma^2} \big) - \big( \frac{\sum_{m=1}^T Z_m^2}{\sigma^2} + \frac{ -2\theta_0 \sum_{m=1}^T Z_m + T\theta_0^2}{\sigma^2}\big)\big) + \frac{\theta^2}{\tau^2} \big] \Big]d\theta $$
$$ = \frac{1}{\sqrt{2\pi\tau^2}} \int_{\theta \in \Theta} \exp \Big[ \frac{-1}{2} \big[ \big( \frac{-2\theta \sum_{m=1}^T Z_m + T\theta^2}{\sigma^2} \big) - \big( \frac{ -2\theta_0 \sum_{m=1}^T Z_m + T\theta_0^2}{\sigma^2}\big)\big) + \frac{\theta^2}{\tau^2} \big] \Big]d\theta $$
$$ = \frac{1}{\sqrt{2\pi\tau^2}} \int_{\theta \in \Theta} \exp \Big[\frac{\theta \sum_{m=1}^T Z_m}{\sigma^2} - \frac{T\theta^2}{2\sigma^2} - \frac{\theta_0 \sum_{m=1}^T Z_m}{\sigma^2} + \frac{T\theta_0^2}{2\sigma^2} - \frac{\theta^2}{2\tau^2} \Big]d\theta $$
$$ = \frac{1}{\sqrt{2\pi\tau^2}} \int_{\theta \in \Theta} \exp \Big[ -\theta^2\Big(\frac{T}{2\sigma^2} + \frac{1}{2\tau^2}\Big) + \theta \Big( \frac{\sum_{m=1}^T Z_m}{\sigma^2} \Big) + \Big(\frac{-\theta_0 \sum_{m=1}^T Z_m}{\sigma^2}+ \frac{T\theta_0^2}{2\sigma^2} \Big)\Big]d\theta $$
At this point, we can let
- $a=\frac{T}{2\sigma^2} + \frac{1}{2\tau^2} = \frac{T\tau^2 + \sigma^2}{2\sigma^2\tau^2}$
- $b= \frac{\sum_{m=1}^T Z_m}{\sigma^2}$
- $c=\frac{-\theta_0 \sum_{m=1}^T Z_m}{\sigma^2}+ \frac{T\theta_0^2}{2\sigma^2} = \frac{-2\theta_0 \sum_{m=1}^T Z_m + T\theta_0^2}{2\sigma^2}$
If $\Theta = \mathbb{R}$
$$ \frac{1}{\sqrt{2\pi\tau^2}} \int_{\theta \in \Theta} e^{-a\theta^2 + b\theta + c} d\theta = \frac{1}{\sqrt{2\pi\tau^2}} \sqrt{\frac{\pi}{a}} \exp \Big(c + \frac{b^2}{4a} \Big) $$
If $\Theta = +\mathbb{R}$, the integral is the same, but with an added factor $\text{erf}\big(\frac{b}{2\sqrt{a}}\big) + 1$.
If $\Theta = -\mathbb{R}$, the integral is the same, but with an added factor $\text{erfc}\big(\frac{b}{2\sqrt{a}}\big)$
These are great results! I means I can simply multiply the two-sided result by a correction factor to find the one-sided result.
Sanity checking my values for $a$, $b$, and $c$
Going back to assuming $\Theta = \mathbb{R}$, here's an attempt to match the literature the literature
$$ \frac{1}{\sqrt{2\pi\tau^2}} \sqrt{\frac{\pi}{a}} \exp \Big(c + \frac{b^2}{4a} \Big) $$
$$ = \frac{1}{\sqrt{2\pi\tau^2}} \sqrt{\frac{\pi}{\big(\frac{T\tau^2 + \sigma^2}{2\sigma^2\tau^2}\big)}} \exp \Big(\big(\frac{-2\theta_0 \sum_{m=1}^T Z_m + T\theta_0^2}{2\sigma^2}\big) + \frac{\big(\frac{\sum_{m=1}^T Z_m}{\sigma^2}\big)^2}{4\big(\frac{T\tau^2 + \sigma^2}{2\sigma^2\tau^2}\big)} \Big) $$
$$ = \frac{1}{\sqrt{2\tau^2}} \sqrt{\frac{1}{\big(\frac{T\tau^2 + \sigma^2}{2\sigma^2\tau^2}\big)}} \exp \Big(\big(\frac{-2\theta_0 \sum_{m=1}^T Z_m + T\theta_0^2}{2\sigma^2}\big) + \frac{\big(\frac{\sum_{m=1}^T Z_m}{\sigma^2}\big)^2}{4\big(\frac{T\tau^2 + \sigma^2}{2\sigma^2\tau^2}\big)} \Big) $$
$$ = \frac{1}{\sqrt{2\tau^2}} \sqrt{\big(\frac{2\sigma^2\tau^2}{T\tau^2 + \sigma^2}\big)} \exp \Big(\big(\frac{-2\theta_0 \sum_{m=1}^T Z_m + T\theta_0^2}{2\sigma^2}\big) + \frac{\big(\frac{\sum_{m=1}^T Z_m}{\sigma^2}\big)^2}{4\big(\frac{T\tau^2 + \sigma^2}{2\sigma^2\tau^2}\big)} \Big) $$
$$ = \sqrt{\frac{\sigma^2}{T\tau^2 + \sigma^2}} \exp \Big(\big(\frac{-2\theta_0 \sum_{m=1}^T Z_m + T\theta_0^2}{2\sigma^2}\big) + \frac{\big(\frac{\sum_{m=1}^T Z_m}{\sigma^2}\big)^2}{4\big(\frac{T\tau^2 + \sigma^2}{2\sigma^2\tau^2}\big)} \Big) $$
$$ = \sqrt{\frac{\sigma^2}{T\tau^2 + \sigma^2}} \exp \Big(\big(\frac{-2\theta_0 \sum_{m=1}^T Z_m + T\theta_0^2}{2\sigma^2}\big) + \frac{\big(\frac{\sum_{m=1}^T Z_m}{\sigma^2}\big)^2}{2\big(\frac{T\tau^2 + \sigma^2}{\sigma^2\tau^2}\big)} \Big) $$
$$ = \sqrt{\frac{\sigma^2}{T\tau^2 + \sigma^2}} \exp \Big(\big(\frac{-2\theta_0 \sum_{m=1}^T Z_m + T\theta_0^2}{2\sigma^2}\big) + \frac{\big(\sum_{m=1}^T Z_m\big)^2}{\sigma^4} \frac{\sigma^2\tau^2}{2\big(T\tau^2 + \sigma^2\big)} \Big) $$
$$ = \sqrt{\frac{\sigma^2}{T\tau^2 + \sigma^2}} \exp \Big(\big(\frac{-2\theta_0 \sum_{m=1}^T Z_m + T\theta_0^2}{2\sigma^2}\big) + \frac{\big(\sum_{m=1}^T Z_m\big)^2 \tau^2}{2\sigma^2\big(T\tau^2 + \sigma^2\big)} \Big) $$
$$ = \sqrt{\frac{\sigma^2}{T\tau^2 + \sigma^2}} \exp \Big(\big(\frac{-2\theta_0T\bar{Z}_T + T\theta_0^2}{2\sigma^2}\big) + \frac{\big(T\bar{Z}_T\big)^2 \tau^2}{2 \sigma^2\big(T\tau^2 + \sigma^2\big)} \Big) $$
$$ = \sqrt{\frac{\sigma^2}{T\tau^2 + \sigma^2}} \exp \Big(\frac{\big((-2\theta_0T\bar{Z}_T + T\theta_0^2) (T\tau^2 + \sigma^2)\big) + (T\bar{Z}_T)^2 \tau^2}{2\sigma^2(T\tau^2 + \sigma^2)} \Big) $$
$$ = \sqrt{\frac{\sigma^2}{T\tau^2 + \sigma^2}} \exp \Big(\frac{ -2\theta_0(T^2\tau^2)\bar{Z}_T + (T^2\tau^2)\theta_0^2 + \sigma^2\big(-2\theta_0T\bar{Z}_T + T\theta_0^2\big) + (T\bar{Z}_T)^2 \tau^2}{2\sigma^2(T\tau^2 + \sigma^2)} \Big) $$
$$ = \sqrt{\frac{\sigma^2}{T\tau^2 + \sigma^2}} \exp \Big(\frac{ -2\theta_0(T^2\tau^2)\bar{Z}_T + (T^2\tau^2)\theta_0^2 + \sigma^2\big(-2\theta_0T\bar{Z}_T + T\theta_0^2\big) + (\bar{Z}_T)^2 T^2\tau^2}{2\sigma^2(T\tau^2 + \sigma^2)} \Big) $$
$$ = \sqrt{\frac{\sigma^2}{T\tau^2 + \sigma^2}} \exp \Big(\frac{T^2\tau^2\Big((\bar{Z}_T)^2 -2\theta_0\bar{Z}_T + \theta_0^2\Big) + \sigma^2\big(-2\theta_0T\bar{Z}_T + T\theta_0^2\big)}{2\sigma^2(T\tau^2 + \sigma^2)} \Big) $$
$$ = \sqrt{\frac{\sigma^2}{T\tau^2 + \sigma^2}} \exp \Big(\frac{T^2\tau^2\Big(\bar{Z}_T - \theta_0\Big)^2 + \sigma^2\big(-2\theta_0T\bar{Z}_T + T\theta_0^2\big)}{2\sigma^2(T\tau^2 + \sigma^2)} \Big) $$
$$ = \sqrt{\frac{\sigma^2}{T\tau^2 + \sigma^2}} \exp \Big(\frac{T^2\tau^2\Big(\bar{Z}_T - \theta_0\Big)^2}{2\sigma^2(T\tau^2 + \sigma^2)} + \frac{\sigma^2\big(-2\theta_0T\bar{Z}_T + T\theta_0^2\big)}{2\sigma^2(T\tau^2 + \sigma^2)} \Big) $$
Problem
For the general case where $\theta_0 \neq 0$, then $\frac{\sigma^2\big(-2\theta_0T\bar{Z}_T + T\theta_0^2\big)}{2\sigma^2(T\tau^2 + \sigma^2)}$ does not equal 0, and so the result in the paper doesn't match what I have here.
It's possible I have a mistake somewhere, but I have PORED over this derivation for literally hours and haven't found the solution. I have tried using SymPy to check my work, but I'm finding it finicky.