3
$\begingroup$

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).

enter image description here enter image description here

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) $$

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.

$\endgroup$
3
  • 1
    $\begingroup$ When you use approximately 30 lines of complex algebraic expressions to complete the square in a quadratic form, chances are excellent anyone will make a difficult-to-detect error somewhere. This problem is truly simple, because the original integrand is some constant multiple of the exponential of a quadratic function of the variable $\theta,$ implying the integral is a Normal CDF (a version of erf) and that its value depends only on the coefficient of $\theta^2$ (and the constant multiplier). You can write down the answer by inspection! $\endgroup$
    – whuber
    Commented Mar 28, 2023 at 15:13
  • $\begingroup$ Hmmm, that's insightful and helpful, but I didn't know the "trick" before you told me. Where did you learn this? Where can I go to learn this for myself? $\endgroup$ Commented Mar 28, 2023 at 17:40
  • $\begingroup$ See google.com/…. I remember learning this in a second-year high school algebra course a very long time ago ;-), but math hasn't changed a lot during that time and I suppose a good textbook at that level might be handy. $\endgroup$
    – whuber
    Commented Mar 28, 2023 at 20:27

1 Answer 1

2
$\begingroup$

This question asks how to evaluate the integral

$$\int_{\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}} \,\mathrm d\theta$$

By adopting a suitable notation and aiming to put the integral into a particularly convenient form, we can make short work of its evaluation. It all comes down to completing the square, which is a matter of adding up the coefficients of powers of $\theta$ appearing in the exponentials.


The rules of exponentiation tell us this integrand must reduce to the exponential of a quadratic form $-Q(\theta)/2,$ which is (as we shall see) most conveniently expressed by "completing the square" as

$$Q(\theta) = s\left[\frac{1}{\beta^2}\theta^2 - \frac{2\alpha}{\beta^2}\theta + \left(\frac{\alpha^2}{\beta^2}+\gamma\right)\right] = s\left(\frac{\theta - \alpha}{\beta}\right)^2 + s\gamma$$

(with $\beta \gt 0$ and $s=\pm 1$) because the change of variable $x = (\theta-\alpha)/\beta,$ entailing $\mathrm d\theta = \beta\,\mathrm dx,$ yields

$$\int_\Theta e^{-Q(\theta)/2}\,\mathrm d\theta = \int_\Theta \exp\left(-s\left(\frac{\theta - \alpha}{\beta}\right)^2/2 - s\gamma/2\right)\,\mathrm d\theta = \beta\, e^{-s\gamma/2}\int_{\mathcal X} e^{-sx^2/2}\,\mathrm dx.$$

where $\mathcal X$ is the image of $\Theta$ under the mapping $\theta\to (\theta-\alpha)/\beta = x.$ Assuming the sign of the form is $s=+1,$ the integral of $\exp(-sx^2/2)$ over all the real numbers is $C=\sqrt{2\pi}.$ (The case $s=-1$ will not arise in these probability calculations and I have excluded the possibility that $Q$ is a linear function of $\theta$ because that reduces the integrand to an exponential, which is elementary to compute.)

We can therefore relate this integral to a probability measure by introducing this normalizing factor of $C,$ resulting in

$$\int_\Theta e^{-Q(\theta)/2}\,\mathrm d\theta = \left(\beta\,e^{-\gamma/2}\sqrt{2\pi}\right) \frac{1}{\sqrt{2\pi}}\int_{\mathcal X} e^{-x^2/2}\,\mathrm dx = \beta\,e^{-\gamma/2}\,\sqrt{2\pi}\, \Phi(\mathcal X)\tag{*}$$

where $\Phi$ is the standard Normal probability measure.

In many applications $\Theta = \mathbb R,$ whence $\mathcal X = \mathbb R$ without any further computation and $\Phi(\mathcal X) = 1$ because it is a probability measure. The right hand side reduces to a simple function of $\beta$ and $\gamma$ -- you don't even have to compute $\alpha.$


To answer the question specifically, then, we compute the coefficients appearing in $Q.$ By inspection, and writing $Z = Z_1 + Z_2 + \cdots + Z_T$ for that sum, the coefficient of $\theta^2$ is

$$\frac{1}{\beta^2} = \frac{1}{\tau^2} + \sum_{m=1}^T \frac{1}{\sigma^2} = \frac{1}{\tau^2} + \frac{T}{\sigma^2}, \tag{1}$$

the coefficient of $\theta$ is

$$\frac{-2\alpha}{\beta^2} = 0+ \sum_{m=1}^T \frac{-2Z_m}{\sigma^2} = -\frac{2 Z}{\sigma^2},\tag{2}$$

the constant term (within the arguments of the exponentials) is

$$\frac{\alpha^2}{\beta^2}+\gamma = 0 + \sum_{m=1}^T \frac{Z_m^2}{\sigma^2} - \left(\frac{Z_m-\theta_0}{\sigma}\right)^2 = \frac{1}{\sigma^2}\left(2Z\theta_0-T\theta_0^2\right)\tag{3},$$

and a constant term from the factors that multiply the exponentials is just $1/\sqrt{2\pi\tau^2}.$

Simply solve for $\beta,$ $\alpha,$ and then $\gamma$ in that order and plug that into $(*),$ multiplying the result afterwards by $1/\sqrt{2\pi\tau^2}.$

$\endgroup$
4
  • $\begingroup$ Thank you! I appreciate your answer, but have a few clarifying questions $\endgroup$ Commented Mar 29, 2023 at 16:48
  • $\begingroup$ - What do you mean "the standard Normal probability 'measure'". I never took measure theory and don't know what a measure is. - I carefully went over your answer, and it makes sense! I follow it! But it took me a while and I had to go step by step. When you say "by inspection ", it just seems like you're really saying "do those 10+ lines of algebra in your head". I have an undergrad in stats. I really don't know where I need to go to develop the intuition that you folks have. $\endgroup$ Commented Mar 29, 2023 at 17:09
  • 1
    $\begingroup$ "By inspection" means you only need to look at the expression to see and copy everything you need. I have done that for you in equations (1), (2), and (3) to illustrate the process. The "standard Normal probability" measure is exactly as given here: namely, the probability of the event $\mathcal X$ is the integral over $\mathcal X$ of the standard Normal density function $e^{-x^2/2}/\sqrt{2\pi},$ which I know you're familiar with. I doubt you need to develop much intuition, but what might help would be to cultivate certain labor-saving practices in doing algebra, as illustrated here. $\endgroup$
    – whuber
    Commented Mar 29, 2023 at 17:30
  • 1
    $\begingroup$ Using effective notation is one such labor-saving practice. Another I have dubbed the "Principle of Mathematical Laziness," which I have described and illustrated in other posts here on CV. I suspect most people learn these things by doing and watching mathematics, paying attention to economy and clarity of style. $\endgroup$
    – whuber
    Commented Mar 29, 2023 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.