As previously, we have that $\sum_k \hat{h}_k^0 \le 1 + 3\epsilon^0|\Omega^0| + 3\epsilon^1|\Omega^{01}|$, and $\sum_k \hat{h}_k^1 \ge 1$. Thus,

$$ \sum_k (\hat{r}_k - 1) \hat{h}_k^1 \ge \hat{\sigma}^2 - 3 (\epsilon^0|\Omega^0| + \epsilon^1|\Omega^{01}|), $$

which implies

$$ \sum_k (\hat{r}_k - 1) h_k^1 \ge \left(1 - \left(\frac{u}{n^1}\right)^{\frac{1}{4}}\right) \hat{\sigma}^2 - \left(\frac{u}{n^1}\right)^{\frac{1}{4}} - (\epsilon^1 (13|\Omega^1| + 4|\Omega^{01}|) + 3\epsilon^0|\Omega^0|). $$

# A.2 Proof of main lemmas and corollaries

## A.2.1 Proof of Lemma 1

Before proving Lemma 1, we emphasize that when $f^0$ and $f^1$ are positive on $[0, 1]^d$, $\sigma^2$ is finite, and $(\frac{f^1(X_1)}{f^0(X_1)} - 1)$ belongs to $L^2((1-\theta) \times f^0 + \theta \times f^1)$ for all $\theta \in [0, 1]$.

Moreover, under $H_0$, $\mathbb{E} \left[ \left( \frac{f^1(X_1)}{f^0(X_1)} - 1 \right) \right] = 0$, and $\mathbb{V} \left[ \left( \frac{f^1(X_1)}{f^0(X_1)} - 1 \right) \right] = \sigma^2$. Then, the Central Limit Theorem implies that

$$ \frac{\sqrt{n}S_n(\mathbb{X})}{\sqrt{\sigma^2}} \xrightarrow{d} \mathcal{N}(0, 1). $$

Thus, the test presented in Lemma 1 is asymptotically of level $\alpha$.

To prove the second part of the Lemma, we consider alternatives $\theta_n = \frac{h}{\sqrt{n}}$ for some $h > 0$. Let us denote $\mathbb{P}_n$ the law of the sample $X_1, \dots, X_n$ under $H_0$, and $\mathbb{Q}_n$ the law of the sample $X_1, \dots, X_n$ under the alternative indexed by $\theta_n$. Under the assumption that $f^0$ and $f^1$ are positive on $[0, 1]^d$, it is easy to see that the family of models indexed by $\theta$ is differentiable in quadratic mean (using, e.g., Lemma 7.6 in [Vaa98]). Then, using Theorem 7.2 in [Vaa98], we find that

$$ \log \left( \frac{d\mathbb{Q}_n}{d\mathbb{P}_n}(\mathbb{X}) \right) = \frac{h}{\sqrt{n}} \sum_{i \le n} \left( \frac{f^1(X_i)}{f^0(X_i)} - 1 \right) - \frac{h^2}{2n} \sum_{i \le n} \left( \frac{f^1(X_i)}{f^0(X_i)} - 1 \right)^2 + o_{\mathbb{P}_n}(1). $$

The Law of Large Numbers implies that

$$ \frac{h^2}{2n} \sum_{i \le n} \left( \frac{f^1(X_i)}{f^0(X_i)} - 1 \right)^2 \xrightarrow{\mathbb{P}} \frac{h^2 \sigma^2}{2}, $$

and the Central Limit Theorem implies that

$$ \frac{h}{\sqrt{n}} \sum_{i \le n} \left( \frac{f^1(X_i)}{f^0(X_i)} - 1 \right) \xrightarrow{d} \mathcal{N}(0, h^2 \sigma^2). $$

Thus, under $\mathbb{P}_n$,

$$ \left( \begin{array}{c} \sqrt{n}S_n(\mathbb{X}) \\ \log \left( \frac{d\mathbb{Q}_n}{d\mathbb{P}_n}(\mathbb{X}) \right) \end{array} \right) \xrightarrow{d} \mathcal{N} \left( \left( \begin{array}{cc} 0 & \sigma^2 \\ -\frac{h^2\sigma^2}{2} & h\sigma^2 \end{array} \right), \left( \begin{array}{cc} \sigma^2 & h\sigma^2 \\ h\sigma^2 & h^2\sigma^2 \end{array} \right) \right). $$

Now, Le Cam's third Lemma (see, e.g., Example 6.7 in [Vaa98]) implies that under $\mathbb{Q}_n$,

$$ \sqrt{n}S_n(\mathbb{X}) \xrightarrow{d} \mathcal{N}(h\sigma^2, \sigma^2). $$
As previously, we have that $\sum_k \hat{h}_k^0 \le 1 + 3\epsilon^0|\Omega^0| + 3\epsilon^1|\Omega^{01}|$, and $\sum_k \hat{h}_k^1 \ge 1$. Thus,

$$ \sum_k (\hat{r}_k - 1) \hat{h}_k^1 \ge \hat{\sigma}^2 - 3 (\epsilon^0|\Omega^0| + \epsilon^1|\Omega^{01}|), $$

which implies

$$ \sum_k (\hat{r}_k - 1) h_k^1 \ge \left(1 - \left(\frac{u}{n^1}\right)^{\frac{1}{4}}\right) \hat{\sigma}^2 - \left(\frac{u}{n^1}\right)^{\frac{1}{4}} - (\epsilon^1 (13|\Omega^1| + 4|\Omega^{01}|) + 3\epsilon^0|\Omega^0|). $$

## A.2 Proof of main lemmas and corollaries

### A.2.1 Proof of Lemma 1

Before proving Lemma 1, we emphasize that when $f^0$ and $f^1$ are positive on $[0, 1]^d$, $\sigma^2$ is finite, and $(\frac{f^1(X_1)}{f^0(X_1)} - 1)$ belongs to $L^2((1-\theta) \times f^0 + \theta \times f^1)$ for all $\theta \in [0, 1]$.

Moreover, under $H_0$, $\mathbb{E}\left[(\frac{f^1(X_1)}{f^0(X_1)} - 1)\right] = 0$, and $\mathbb{V}\left[(\frac{f^1(X_1)}{f^0(X_1)} - 1)\right] = \sigma^2$. Then, the Central Limit Theorem implies that

$$ \frac{\sqrt{n}S_n(\mathbb{X})}{\sqrt{\sigma^2}} \xrightarrow{d} \mathcal{N}(0, 1). $$

Thus, the test presented in Lemma 1 is asymptotically of level $\alpha$.

To prove the second part of the Lemma, we consider alternatives $\theta_n = \frac{h}{\sqrt{n}}$ for some $h > 0$. Let us denote $\mathbb{P}_n$ the law of the sample $X_1, \dots, X_n$ under $H_0$, and $\mathbb{Q}_n$ the law of the sample $X_1, \dots, X_n$ under the alternative indexed by $\theta_n$. Under the assumption that $f^0$ and $f^1$ are positive on $[0, 1]^d$, it is easy to see that the family of models indexed by $\theta$ is differentiable in quadratic mean (using, e.g., Lemma 7.6 in [Vaa98]). Then, using Theorem 7.2 in [Vaa98], we find that

$$ \log \left( \frac{d\mathbb{Q}_n}{d\mathbb{P}_n}(\mathbb{X}) \right) = \frac{h}{\sqrt{n}} \sum_{i \le n} \left( \frac{f^1(X_i)}{f^0(X_i)} - 1 \right) - \frac{h^2}{2n} \sum_{i \le n} \left( \frac{f^1(X_i)}{f^0(X_i)} - 1 \right)^2 + o_{\mathbb{P}_n}(1). $$

The Law of Large Numbers implies that

$$ \frac{h^2}{2n} \sum_{i \le n} \left( \frac{f^1(X_i)}{f^0(X_i)} - 1 \right)^2 \xrightarrow{\mathbb{P}} \frac{h^2 \sigma^2}{2}, $$

and the Central Limit Theorem implies that

$$ \frac{h}{\sqrt{n}} \sum_{i \le n} \left( \frac{f^1(X_i)}{f^0(X_i)} - 1 \right) \xrightarrow{d} \mathcal{N}(0, h^2 \sigma^2). $$

Thus, under $\mathbb{P}_n$,

$$ \left( \begin{array}{c} \sqrt{n}S_n(\mathbb{X}) \\ \log \left( \frac{d\mathbb{Q}_n}{d\mathbb{P}_n}(\mathbb{X}) \right) \end{array} \right) \xrightarrow{d} \mathcal{N} \left( \left( \begin{array}{cc} 0 & \sigma^2 \\ -\frac{h^2\sigma^2}{2} & h\sigma^2 \end{array} \right), \left( \begin{array}{cc} \sigma^2 & h\sigma^2 \\ h\sigma^2 & h^2\sigma^2 \end{array} \right) \right). $$

Now, Le Cam's third Lemma (see, e.g., Example 6.7 in [Vaa98]) implies that under $\mathbb{Q}_n$,

$$ \sqrt{n}S_n(\mathbb{X}) \xrightarrow{d} \mathcal{N}(h\sigma^2, \sigma^2). $$
Applying Theorem 14.7 in [Vaa98], we find that the power function

$$ \pi_n \left( \frac{h}{\sqrt{n}} \right) = \mathbb{Q}_n \left( S_n(\mathbb{X}) \ge \frac{\sqrt{\sigma^2 \Phi(1-\alpha)^{-1}}}{\sqrt{n}} \right) $$

converges as follows :

$$ \pi_n \left( \frac{h}{\sqrt{n}} \right) \to 1 - \Phi(\Phi^{-1}(1-\alpha) - h\sigma). $$

This concludes the proof of Lemma 1.

### A.2.2 Proof of Lemma 2

Let us define

$$ p_{R_n}^0 = \int_{R_n} f^0(x)dx \quad \text{and} \quad p_{R_n}^1 = \int_{R_n} f^1(x)dx. $$

To prove the first part of the Lemma, note that under $H_0$,

$$ \mathbb{P} \left( \sum_{i \le n} 1\{X_i \in R_n\} = 0 \right) = \exp \left( n \log \left( 1 - p_{R_n}^0 \right) \right). $$

Using the bound $\log(1-x) \ge \frac{-x}{2} \times \frac{2-x}{1-x}$ for $x < 1$, we find that

$$ \mathbb{P} \left( \sum_{i \le n} 1\{X_i \in R_n\} = 0 \right) \ge \exp \left( -np_{R_n}^0 \times \frac{2 - p_{R_n}^0}{2 - 2p_{R_n}^0} \right). $$

Thus, this test has type I error lower than $\alpha$ if

$$ \alpha \ge 1 - \exp \left( -A \times \frac{2n - A}{2(n - A)} \right). $$

This proves the first part of Lemma 2.

To prove the second part of Lemma 2, note that under the alternative $H_1$,

$$ \mathbb{P}_{\theta_n} \left( \sum_{i \le n} 1\{X_i \in R\} = 0 \right) = (1 - \theta p_R^1)^n. $$

Using the bound $\log(1-x) \le \frac{-2x}{2-x}$ for $x \in (0, 1)$, we find that

$$ \begin{aligned} \mathbb{P}_{\theta_n} \left( \sum_{i \le n} 1\{X_i \in R\} = 0 \right) &\le \exp \left( \frac{-2p_R^1 n\theta}{2 - p_R^1 \theta} \right) \\ &\le \exp \left( \frac{-2Bn^{1-\gamma}\theta}{2 - n^{-\gamma}\theta} \right). \end{aligned} $$

Thus, to ensure that the test has power $\beta$, it is enough to have

$$ \frac{2Bn^{1-\gamma}\theta}{2 - n^{-\gamma}\theta} \ge \log(1/\beta). $$

This is in particular verified if $\theta \ge \frac{\log(1/\beta)}{Bn^{1-\gamma}}$.
Applying Theorem 14.7 in [Vaa98], we find that the power function

$$ \pi_n \left( \frac{h}{\sqrt{n}} \right) = \mathbb{Q}_n \left( S_n(X) \ge \frac{\sqrt{\sigma^2 \Phi(1-\alpha)^{-1}}}{\sqrt{n}} \right) $$

converges as follows :

$$ \pi_n \left( \frac{h}{\sqrt{n}} \right) \to 1 - \Phi(\Phi^{-1}(1-\alpha) - h\sigma). $$

This concludes the proof of Lemma 1.

### A.2.2 Proof of Lemma 2

Let us define

$$ p_{R_n}^0 = \int_{R_n} f^0(x)dx \quad \text{and} \quad p_{R_n}^1 = \int_{R_n} f^1(x)dx. $$

To prove the first part of the Lemma, note that under $H_0$,

$$ \mathbb{P} \left( \sum_{i \le n} 1\{X_i \in R_n\} = 0 \right) = \exp \left( n \log \left( 1 - p_{R_n}^0 \right) \right). $$

Using the bound $\log(1-x) \ge \frac{-x}{2} \times \frac{2-x}{1-x}$ for $x < 1$, we find that

$$ \mathbb{P} \left( \sum_{i \le n} 1\{X_i \in R_n\} = 0 \right) \ge \exp \left( -np_{R_n}^0 \times \frac{2 - p_{R_n}^0}{2 - 2p_{R_n}^0} \right). $$

Thus, this test has type I error lower than $\alpha$ if

$$ \alpha \ge 1 - \exp \left( -A \times \frac{2n - A}{2(n - A)} \right). $$

This proves the first part of Lemma 2.

To prove the second part of Lemma 2, note that under the alternative $H_1$,

$$ \mathbb{P}_{\theta_n} \left( \sum_{i \le n} 1\{X_i \in R\} = 0 \right) = (1 - \theta p_R^1)^n. $$

Using the bound $\log(1-x) \le \frac{-2x}{2-x}$ for $x \in (0, 1)$, we find that

$$ \mathbb{P}_{\theta_n} \left( \sum_{i \le n} 1\{X_i \in R\} = 0 \right) \le \exp \left( \frac{-2p_R^1 n\theta}{2 - p_R^1 \theta} \right) \\ \le \exp \left( \frac{-2Bn^{1-\gamma}\theta}{2 - n^{-\gamma}\theta} \right). $$

Thus, to ensure that the test has power $\beta$, it is enough to have

$$ \frac{2Bn^{1-\gamma}\theta}{2 - n^{-\gamma}\theta} \ge \log(1/\beta). $$

This is in particular verified if $\theta \ge \frac{\log(1/\beta)}{Bn^{1-\gamma}}$.
### A.2.3 Proof of Lemma 3

Recall that $\hat{\sigma}_{\mathcal{P}}^1$ is assumed to be finite. Defining $\mathcal{B} = \{k : h_k^0 > 0\}$ and $\bar{\mathcal{B}} = \{k : h_k^0 = 0\}$, we see that $\{k : h_k^1 = 0\} \subset \bar{\mathcal{B}}$. This implies in particular that $\Omega^0 = \emptyset$, and that $\bar{\mathcal{B}} \subset \Omega^{01}$. Now, for all $k \in \Omega^{01}$, $\hat{r}_k = 1$, so

$$ 
\begin{aligned}
\hat{\sigma}^2 &= \sum_{k \in \mathcal{B}} \left( \frac{\hat{h}_k^1}{\hat{h}_k^0} - 1 \right)^2 \hat{h}_k^0 \\
&= \sum_{k \in \mathcal{B}} \left( \frac{(\hat{h}_k^1)^2}{\hat{h}_k^0} - 2\hat{h}_k^1 + \hat{h}_k^0 \right).
\end{aligned}
$$

Using $|\sum_{k \in \mathcal{B}} \hat{h}_k^1 - 1| \le \epsilon^1 (|\Omega^1| + |\Omega^{01}|)$ and $|\sum_{k \in \mathcal{B}} \hat{h}_k^0 - 1| \le \epsilon^1 |\Omega^{01}|$, we find
$$ \left| \hat{\sigma}^2 - \left( \sum_{k \notin \bar{\mathcal{B}}} \frac{(\hat{h}_k^1)^2}{\hat{h}_k^0} - 1 \right) \right| \le 5\epsilon^1 |\Omega|. $$

Similarly, we have $\hat{\sigma}_{\mathcal{P}}^2 = \sum_{k \in \mathcal{B}} \frac{(h_k^1)^2}{h_k^0} - 1$. Combining these expressions, we find that

$$ 
\begin{aligned}
|\hat{\sigma}^2 - \bar{\sigma}_{\mathcal{P}}^2| &\le 5\epsilon^1 |\Omega| + \sum_{k \in \mathcal{B}} \left| \frac{(\hat{h}_k^1)^2}{\hat{h}_k^0} - \frac{(h_k^1)^2}{h_k^0} \right| \\
&\le 5\epsilon^1 |\Omega| + \sum_{k \in \mathcal{B}} \frac{|\hat{h}_k^1 - h_k^1| (\hat{h}_k^1 + h_k^1)}{h_k^0} + \sum_{k \in \mathcal{B}} \left| \frac{h_k^0}{\hat{h}_k^0} - 1 \right| h_k^0 \hat{h}_k^1
\end{aligned}
$$

Now, Lemma 8 shows that on the event $\mathcal{E}$, for all $k \notin \Omega^1 \cup \Omega^{01}$

$$ |\hat{h}_k^1 - h_k^1| \le \sqrt{\frac{10u}{n^1}}. $$

On the other hand, for all $k \in \Omega^1 \cup \Omega^{01}$,

$$ |\hat{h}_k^1 - h_k^1| \le 3\epsilon^1 \le \sqrt{\frac{27u}{n^1}}. $$

Moreover, Lemma 8 shows that on the event $\mathcal{E}$, $h_k^1 \le 3\hat{h}_k^1$. Thus,

$$ \sum_{k \in \mathcal{B}} \frac{|\hat{h}_k^1 - h_k^1| (\hat{h}_k^1 + h_k^1)}{\hat{h}_k^0} \le \sqrt{\frac{27u}{n^1}} \sum_{k \in \mathcal{B}} \frac{4h_k^1}{h_k^0}. $$

Similarly, Lemma 8 reveals that for all $k$,

$$ \left| \frac{h_k^0}{\hat{h}_k^0} - 1 \right| \le \frac{\sqrt{\frac{2u}{n^0 h_k^0}} + \frac{u}{3n^0 h_k^0}}{1 - \sqrt{\frac{2u}{n^0 h_k^0}} - \frac{u}{3n^0 h_k^0}}. $$
### A.2.3 Proof of Lemma 3

Recall that $\hat{\sigma}_P^1$ is assumed to be finite. Defining $\mathcal{B} = \{k : h_k^0 > 0\}$ and $\bar{\mathcal{B}} = \{k : h_k^0 = 0\}$, we see that $\{k : h_k^1 = 0\} \subset \bar{\mathcal{B}}$. This implies in particular that $\Omega^0 = \emptyset$, and that $\bar{\mathcal{B}} \subset \Omega^{01}$. Now, for all $k \in \Omega^{01}$, $\hat{r}_k = 1$, so

$$ \begin{aligned} \hat{\sigma}^2 &= \sum_{k \in \mathcal{B}} \left( \frac{\hat{h}_k^1}{\hat{h}_k^0} - 1 \right)^2 \hat{h}_k^0 \\ &= \sum_{k \in \mathcal{B}} \left( \frac{(\hat{h}_k^1)^2}{\hat{h}_k^0} - 2\hat{h}_k^1 + \hat{h}_k^0 \right). \end{aligned} $$

Using $|\sum_{k \in \mathcal{B}} \hat{h}_k^1 - 1| \le \epsilon^1 (|\Omega^1| + |\Omega^{01}|)$ and $|\sum_{k \in \mathcal{B}} \hat{h}_k^0 - 1| \le \epsilon^1 |\Omega^{01}|$, we find

$$ \left| \hat{\sigma}^2 - \left( \sum_{k \notin \bar{\mathcal{B}}} \frac{(\hat{h}_k^1)^2}{\hat{h}_k^0} - 1 \right) \right| \le 5\epsilon^1 |\Omega|. $$

Similarly, we have $\bar{\sigma}_P^2 = \sum_{k \in \mathcal{B}} \frac{(h_k^1)^2}{h_k^0} - 1$. Combining these expressions, we find that

$$ \begin{aligned} |\hat{\sigma}^2 - \bar{\sigma}_P^2| &\le 5\epsilon^1 |\Omega| + \sum_{k \in \mathcal{B}} \left| \frac{(\hat{h}_k^1)^2}{\hat{h}_k^0} - \frac{(h_k^1)^2}{h_k^0} \right| \\ &\le 5\epsilon^1 |\Omega| + \sum_{k \in \mathcal{B}} \frac{|\hat{h}_k^1 - h_k^1| (\hat{h}_k^1 + h_k^1)}{h_k^0} + \sum_{k \in \mathcal{B}} \left| \frac{h_k^0}{\hat{h}_k^0} - 1 \right| h_k^0 \hat{h}_k^1 \end{aligned} $$

Now, Lemma 8 shows that on the event $\mathcal{E}$, for all $k \notin \Omega^1 \cup \Omega^{01}$

$$ |\hat{h}_k^1 - h_k^1| \le \sqrt{\frac{10u}{n^1}}. $$

On the other hand, for all $k \in \Omega^1 \cup \Omega^{01}$,

$$ |\hat{h}_k^1 - h_k^1| \le 3\epsilon^1 \le \sqrt{\frac{27u}{n^1}}. $$

Moreover, Lemma 8 shows that on the event $\mathcal{E}$, $h_k^1 \le 3\hat{h}_k^1$. Thus,

$$ \sum_{k \in \mathcal{B}} \frac{|\hat{h}_k^1 - h_k^1| (\hat{h}_k^1 + h_k^1)}{\hat{h}_k^0} \le \sqrt{\frac{27u}{n^1}} \sum_{k \in \mathcal{B}} \frac{4h_k^1}{h_k^0}. $$

Similarly, Lemma 8 reveals that for all $k$,

$$ \left| \frac{h_k^0}{\hat{h}_k^0} - 1 \right| \le \frac{\sqrt{\frac{2u}{n^0 h_k^0}} + \frac{u}{3n^0 h_k^0}}{1 - \sqrt{\frac{2u}{n^0 h_k^0}} - \frac{u}{3n^0 h_k^0}}. $$
This proves that

$$|\hat{\sigma}^2 - \bar{\sigma}_P^2| \le 5\sqrt{\frac{3u}{n^1}}|\Omega| + \sqrt{\frac{27u}{n^1}}\sum_{k \in \mathcal{B}} \frac{2h_k^1}{h_k^0} + \sum_{k \in \mathcal{B}} \frac{\sqrt{\frac{2uh_k^0}{n^0}} + \frac{uh_k^0}{3n^0}}{1 - \sqrt{\frac{2u}{n^0h_k^0}} - \frac{u}{3n^0h_k^0}}$$

Now, for all $k \in \mathcal{B}$, $h_k^0$ is strictly positive. Then, for $n^0, n^1$ and $n$ large enough, $\min_k(h_k^0 - \sqrt{2\frac{uh_k^0}{n^0}} - \frac{u}{3n^0}) > \epsilon^1$, so $\Omega^{01} \cap \mathcal{B} = \emptyset$. When $n^0$ is large enough so that $\sqrt{\frac{2uh_k^0}{n^0}} + \frac{uh_k^0}{3n^0} \le 1/2$, there exists a constant $C_{\bar{f}_P, \bar{f}_P, K}$ depending only on $\bar{f}_P^0, \bar{f}_P^1$, and $K$ such that

$$|\hat{\sigma}^2 - \bar{\sigma}_P^2| \le C_{\bar{f}_P^0, \bar{f}_P^1, K} \left( \sqrt{\frac{u}{n^1}} + \sqrt{\frac{u}{n^0}} \right).$$

### A.2.4 Proof of Corollary 1

Let us assume that $n, n^0$ and $n^1$ are large enough so that Lemma 3 holds, and that on the event $\mathcal{E}$,

$$|\hat{\sigma}^2 - \bar{\sigma}_P^2| \le \frac{\bar{\sigma}_P^2}{2}.$$

Arguments similar to that of Lemma 3 show that for $n, n^0$ and $n^1$ large enough, $K^0 = K^1 = 0$. Moreover, for $n, n^0$ and $n^1$ large enough, $K^0 \sqrt{\frac{u}{n^0\bar{\sigma}^2}} \le \sqrt{K}$ and $K^0 \sqrt{\frac{t}{n\bar{\sigma}^2}} \le 1$. Then, Theorem 1 proves that the Density Ratio Test has power $1 - \alpha$ against alternatives such that

$$\theta \ge \frac{C\sqrt{K(u \vee t)}}{\bar{\sigma}_P^2} \left( \sqrt{\frac{1}{n}} + \sqrt{\frac{1}{n^0}} \right).$$

### A.2.5 Proof of Lemma 4

The proof of Lemma 7 follows from noticing that if $h_k^1 \ge \sqrt{\frac{5u}{n^1}}$, Lemma 8 implies that on $\mathcal{E}$, $\frac{N_k^1}{n^1} > \sqrt{\frac{3u}{n^1}}$, so $k \notin \Omega^1 \cup \Omega^{01}$. On the other hand, the same reasoning as in the proof of Lemma 10 shows that this implies that $\hat{h}_k^1 \ge h_k^1 \left(1 - \left(\frac{u}{n^1}\right)^{\frac{1}{4}}\right)$. Moreover, since $\sqrt{\frac{5u}{n^1}} \le 1$, $\left(1 - \left(\frac{u}{n^1}\right)^{\frac{1}{4}}\right) \ge \frac{1}{3}$. Thus,

$$\hat{\sigma}^2 \ge \frac{(\hat{h}_k^1)^2}{\hat{h}_k^0} \ge \left(1 - \left(\frac{u}{n^1}\right)^{\frac{1}{4}}\right)^2 \frac{(h_k^1)^2}{\epsilon^0} \ge \frac{(h_k^1)^2}{3\epsilon^0}.$$

Now, applying Theorem 1, we find that the Density Ratio Test has power $1 - \alpha$ against alternatives such that

$$\theta \ge CK \left( \sqrt{\frac{t}{n\hat{\sigma}^2}} + \frac{\sqrt{u}}{\hat{\sigma}^2\sqrt{n^1}} + \sqrt{\frac{u}{n^0\hat{\sigma}^2}} \right).$$

Note that

$$\frac{\sqrt{u}}{\hat{\sigma}^2\sqrt{n^1}} \le \sqrt{\frac{5u}{n^1}} \times \frac{3\epsilon^0}{\sqrt{5}h_1^2}.$$

Since $\sqrt{n^1}h_k^1 \ge 1$,

$$\frac{\sqrt{u}}{\hat{\sigma}^2\sqrt{n^1}} \le \frac{2\epsilon^0}{h_1}.$$
This proves that

$$|\hat{\sigma}^2 - \bar{\sigma}_P^2| \le 5\sqrt{\frac{3u}{n^1}}|\Omega| + \sqrt{\frac{27u}{n^1}} \sum_{k \in \mathcal{B}} \frac{2h_k^1}{h_k^0} + \sum_{k \in \mathcal{B}} \frac{\sqrt{\frac{2uh_k^0}{n^0}} + \frac{uh_k^0}{3n^0}}{1 - \sqrt{\frac{2u}{n^0h_k^0}} - \frac{u}{3n^0h_k^0}}$$

Now, for all $k \in \mathcal{B}$, $h_k^0$ is strictly positive. Then, for $n^0, n^1$ and $n$ large enough, $\min_k(h_k^0 - \sqrt{2\frac{uh_k^0}{n^0}} - \frac{u}{3n^0}) > \epsilon^1$, so $\Omega^{01} \cap \mathcal{B} = \emptyset$. When $n^0$ is large enough so that $\sqrt{\frac{2uh_k^0}{n^0}} + \frac{uh_k^0}{3n^0} \le 1/2$, there exists a constant $C_{\bar{f}_P, \bar{f}_P, K}$ depending only on $\bar{f}_P^0, \bar{f}_P^1$, and $K$ such that

$$|\hat{\sigma}^2 - \bar{\sigma}_P^2| \le C_{\bar{f}_P^0, \bar{f}_P^1, K} \left( \sqrt{\frac{u}{n^1}} + \sqrt{\frac{u}{n^0}} \right).$$

### A.2.4 Proof of Corollary 1

Let us assume that $n, n^0$ and $n^1$ are large enough so that Lemma 3 holds, and that on the event $\mathcal{E}$,

$$|\hat{\sigma}^2 - \bar{\sigma}_P^2| \le \frac{\bar{\sigma}_P^2}{2}.$$

Arguments similar to that of Lemma 3 show that for $n, n^0$ and $n^1$ large enough, $K^0 = K^1 = 0$. Moreover, for $n, n^0$ and $n^1$ large enough, $K^0 \sqrt{\frac{u}{n^0\bar{\sigma}^2}} \le \sqrt{K}$ and $K^0 \sqrt{\frac{t}{n\bar{\sigma}^2}} \le 1$. Then, Theorem 1 proves that the Density Ratio Test has power $1 - \alpha$ against alternatives such that

$$\theta \ge \frac{C\sqrt{K(u \vee t)}}{\bar{\sigma}_P^2} \left( \sqrt{\frac{1}{n}} + \sqrt{\frac{1}{n^0}} \right).$$

### A.2.5 Proof of Lemma 4

The proof of Lemma 7 follows from noticing that if $h_k^1 \ge \sqrt{\frac{5u}{n^1}}$, Lemma 8 implies that on $\mathcal{E}$, $\frac{N_k^1}{n^1} > \sqrt{\frac{3u}{n^1}}$, so $k \notin \Omega^1 \cup \Omega^{01}$. On the other hand, the same reasoning as in the proof of Lemma 10 shows that this implies that $\hat{h}_k^1 \ge h_k^1 \left(1 - \left(\frac{u}{n^1}\right)^{\frac{1}{4}}\right)$. Moreover, since $\sqrt{\frac{5u}{n^1}} \le 1$, $\left(1 - \left(\frac{u}{n^1}\right)^{\frac{1}{4}}\right) \ge \frac{1}{3}$. Thus,

$$\hat{\sigma}^2 \ge \frac{(\hat{h}_k^1)^2}{\hat{h}_k^0} \ge \left(1 - \left(\frac{u}{n^1}\right)^{\frac{1}{4}}\right)^2 \frac{(h_k^1)^2}{\epsilon^0} \ge \frac{(h_k^1)^2}{3\epsilon^0}.$$

Now, applying Theorem 1, we find that the Density Ratio Test has power $1 - \alpha$ against alternatives such that

$$\theta \ge CK \left( \sqrt{\frac{t}{n\hat{\sigma}^2}} + \frac{\sqrt{u}}{\hat{\sigma}^2\sqrt{n^1}} + \sqrt{\frac{u}{n^0\hat{\sigma}^2}} \right).$$

Note that

$$\frac{\sqrt{u}}{\hat{\sigma}^2\sqrt{n^1}} \le \sqrt{\frac{5u}{n^1}} \times \frac{3\epsilon^0}{\sqrt{5}h_1^2}.$$

Since $\sqrt{n^1}h_k^1 \ge 1$,

$$\frac{\sqrt{u}}{\hat{\sigma}^2\sqrt{n^1}} \le \frac{2\epsilon^0}{h_1}.$$
Moreover, $\epsilon^0 = \frac{t}{n} \lor \frac{3u}{n^0}$, so the Density Ratio Test has power $1 - \alpha$ against alternatives such that

$$ \theta \geq \frac{C_{\alpha,K} \epsilon^0}{h_k^1} $$

for some constant $C_{\alpha,K}$ depending on $\alpha$ and $K$.

### A.2.6 Proof of Corollary 2

First, we note that by construction, there are at most $2K_{max}$ different bins in the partition sequence $(\mathcal{P}_K) k \le K_{max})$, and that those nodes correspond to inner and outer node of the tree corresponding to $\mathcal{P}_{K_{max}}$. Therefore, to control the error of $h_k^0$ and $h_k^1$ uniformly for all bins $k$ in all $K_{max}$ partitions $\mathcal{P}_K$, it is enough to control the error of $h_k^0$ and $h_k^1$ for the $2K_{max}$ bins $k$ corresponding to inner and outer nodes of the largest tree. We choose $u = \log(8K_{max}/\alpha)$ and $t = \log(2/\alpha)$, and we follow the same proof as in Lemma 8 to show that the error bounds hold with the same probabilities for all bins in partition $\mathcal{P}_{K^*}$. Then, the control of the type I and type II error follows similarly.

### A.2.7 Signal decreases after approximation

In this Section, we show that approximating the densities $f^0$ and $f^1$ using piece-wise constant functions leads to a decrease in the test signal.

**Lemma 11.** For all functions $f^0, f^1$ positive on $[0, 1]^d$, and for all partition $\mathcal{P}$ of $[0, 1]^d$,

$$ \bar{\sigma}_{\mathcal{P}}^2 \le \sigma^2. $$

*Proof.* Note that it is enough to show that for all bin $B_k$ of partition $\mathcal{P}$,

$$ \left(\frac{h_k^1}{h_k^0} - 1\right)^2 h_k^0 \le \int_{B_k} \left(\frac{f^1(x)}{f^0(x)} - 1\right)^2 f^0(x) dx. $$

The results will follow by summing over the different intervals. Now,

$$ \left(\frac{h_k^1}{h_k^0} - 1\right)^2 h_k^0 = \frac{h_k^0}{(h_k^1)^2} + 2h_k^1 - h_k^0, $$

and

$$ \begin{aligned} \int_{B_k} \left( \frac{f^1(x)}{f^0(x)} - 1 \right)^2 f^0(x) dx &= \int_{B_k} \frac{f^1(x)^2}{f^0(x)} dx - 2 \int_{B_k} f^1(x) dx + \int_{B_k} f^0(x) dx \\ &= \int_{B_k} \frac{f^1(x)^2}{f^0(x)} dx - 2h_k^1 + h_k^0 dx. \end{aligned} $$

We conclude the proof by showing that $h_k^0 \le \int_{B_k} \frac{f^1(x)^2}{f^0(x)} dx$. To do so, note that

$$ \begin{aligned} (h_k^1)^2 &= \left( \int_{B_k} f^1(x) dx \right)^2 \\ &= \left( \int_{B_k} \frac{f^1(x)}{\sqrt{f^0(x)}} \sqrt{f^0(x)} dx \right)^2. \end{aligned} $$
Moreover, $\epsilon^0 = \frac{t}{n} \lor \frac{3u}{n^0}$, so the Density Ratio Test has power $1 - \alpha$ against alternatives such that

$$ \theta \geq \frac{C_{\alpha,K} \epsilon^0}{h_k^1} $$

for some constant $C_{\alpha,K}$ depending on $\alpha$ and $K$.

### A.2.6 Proof of Corollary 2

First, we note that by construction, there are at most $2K_{max}$ different bins in the partition sequence $(\mathcal{P}_K) k \le K_{max})$, and that those nodes correspond to inner and outer node of the tree corresponding to $\mathcal{P}_{K_{max}}$. Therefore, to control the error of $h_k^0$ and $h_k^1$ uniformly for all bins $k$ in all $K_{max}$ partitions $\mathcal{P}_K$, it is enough to control the error of $h_k^0$ and $h_k^1$ for the $2K_{max}$ bins $k$ corresponding to inner and outer nodes of the largest tree. We choose $u = \log(8K_{max}/\alpha)$ and $t = \log(2/\alpha)$, and we follow the same proof as in Lemma 8 to show that the error bounds hold with the same probabilities for all bins in partition $\mathcal{P}_{K^*}$. Then, the control of the type I and type II error follows similarly.

### A.2.7 Signal decreases after approximation

In this Section, we show that approximating the densities $f^0$ and $f^1$ using piece-wise constant functions leads to a decrease in the test signal.

**Lemma 11.** For all functions $f^0, f^1$ positive on $[0, 1]^d$, and for all partition $\mathcal{P}$ of $[0, 1]^d$,

$$ \bar{\sigma}_{\mathcal{P}}^2 \le \sigma^2. $$

*Proof.* Note that it is enough to show that for all bin $B_k$ of partition $\mathcal{P}$,

$$ \left(\frac{h_k^1}{h_k^0} - 1\right)^2 h_k^0 \le \int_{B_k} \left(\frac{f^1(x)}{f^0(x)} - 1\right)^2 f^0(x)dx. $$

The results will follow by summing over the different intervals. Now,

$$ \left(\frac{h_k^1}{h_k^0} - 1\right)^2 h_k^0 = \frac{h_k^0}{(h_k^1)^2} + 2h_k^1 - h_k^0, $$

and

$$ \begin{aligned} \int_{B_k} \left( \frac{f^1(x)}{f^0(x)} - 1 \right)^2 f^0(x) dx &= \int_{B_k} \frac{f^1(x)^2}{f^0(x)} dx - 2 \int_{B_k} f^1(x) dx + \int_{B_k} f^0(x) dx \\ &= \int_{B_k} \frac{f^1(x)^2}{f^0(x)} dx - 2h_k^1 + h_k^0 dx. \end{aligned} $$

We conclude the proof by showing that $h_k^0 \le \int_{B_k} \frac{f^1(x)^2}{f^0(x)} dx$. To do so, note that

$$ \begin{aligned} (h_k^1)^2 &= \left( \int_{B_k} f^1(x) dx \right)^2 \\ &= \left( \int_{B_k} \frac{f^1(x)}{\sqrt{f^0(x)}} \sqrt{f^0(x)} dx \right)^2. \end{aligned} $$
Applying Cauchy-Schwarz inequality, we find

$$ (h_k^1)^2 \le \int_{B_k} \frac{f^1(x)^2}{f^0(x)} dx \int_{B_k} f^0(x) dx $$

so

$$ \frac{(h_k^1)^2}{h_k^0} \le \int_{B_k} \left( \frac{f^1(x)}{\sqrt{f^0(x)}} \right)^2 dx, $$

which proves the claim.

□

# B Additional simulations

## B.1 Robustness in the case of mixture model $f^0$

In some scenarios, there might be reasons to suspect that the distribution $f^0$ could undergo changes between the training and test phases. For instance, in the context of flow cytometry data, $f^0$ may be viewed as a multi-modal distribution, with each mode corresponding to a different type of cell. In contrast, $f^1$ is often a uni-modal distribution representing a specific type of cells of interest. The proportions of the different cell types in $f^0$ can vary between individuals, and $f^0$ may be more accurately modeled as a mixture distribution with varying proportions of its components. In the following experiment, we explore the robustness of the Density Ratio Test in the face of this phenomenon.

More precisely, we consider $f^0$ as a mixture of two truncated Gaussians, denoted as $g_a$ and $g_b$, with covariance matrix $\begin{pmatrix} 1/100 & 0 \\ 0 & 1/100 \end{pmatrix}$ and means equal to (3/10, 6/10) and (6/10, 3/10), respectively. The distribution $f^1$ is chosen as in Setting 2: a truncated Gaussian with covariance matrix $\begin{pmatrix} 1/100 & 0 \\ 0 & 1/100 \end{pmatrix}$ and mean equal to (6/10, 6/10). We set the training sample size $n^0 + n^1$ to 1000000 with $n^0 = 0.7 \times (n^{train})$. We investigate the type I error of the test, as well as its power against alternatives $\theta = 0.015$. In the first scenario, we assume that at training time, $f^0 = 0.5 \times g_a + 0.5 \times g_b$, while in the test sample, $f^0 = \pi \times g_a + (1 - \pi) \times g_b$ for $\pi$ varying from 0.5 to 0.9. In the second scenario, we assume that at training time, $f^0 = \pi \times g_a + (1 - \pi) \times g_b$ for $\pi$ varying from 0.5 to 0.9, while in the test sample, $f^0 = 0.5 \times g_a + 0.5 \times g_b$. Each experiment is reproduced 300 times. The results are presented in Tables 1 and 2, respectively.

<table><caption>Table 1: Proportion of experiments where $H_0$ is rejected. The training sample $X^0$ has distribution $f^0 = 0.5 \times g_a + 0.5 \times g_b$, while for the test sample $f^0 = \pi \times g_a + (1 - \pi) \times g_b$.</caption><thead><tr><th>π</th><th>0.5</th><th>0.6</th><th>0.7</th><th>0.8</th><th>0.9</th></tr></thead><tbody><tr><td>Proportion of rejects under H<sub>0</sub></td><td>0.00</td><td>0.00</td><td>0.00</td><td>0.00</td><td>0.00</td></tr><tr><td>Proportion of rejects under H<sub>1</sub> with θ = 0.015</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr></tbody></table>

The results presented in Table 1 indicate a certain robustness of the Density Ratio Test against reasonable variations in the proportions of the components of the mixture distribution $f^0$. Indeed, the type I error remains lower than the desired level $\alpha = 0.05$ for all proportions considered in the first experiment, and as long as $\pi \ge 0.2$ in the second experiment. This should come as no surprise: the partition chosen by our algorithm favors bins where the density under $f^0$ is low, while the density under $f^1$ is relatively large. When such bins exist, they contain the majority of the signal and carry the most weight in the test, leading to rejection of the hypothesis when the number
Applying Cauchy-Schwarz inequality, we find

$$ (h_k^1)^2 \le \int_{B_k} \frac{f^1(x)^2}{f^0(x)} dx \int_{B_k} f^0(x) dx $$

so

$$ \frac{(h_k^1)^2}{h_k^0} \le \int_{B_k} \left( \frac{f^1(x)}{\sqrt{f^0(x)}} \right)^2 dx, $$

which proves the claim.

□

# B Additional simulations

## B.1 Robustness in the case of mixture model $f^0$

In some scenarios, there might be reasons to suspect that the distribution $f^0$ could undergo changes between the training and test phases. For instance, in the context of flow cytometry data, $f^0$ may be viewed as a multi-modal distribution, with each mode corresponding to a different type of cell. In contrast, $f^1$ is often a uni-modal distribution representing a specific type of cells of interest. The proportions of the different cell types in $f^0$ can vary between individuals, and $f^0$ may be more accurately modeled as a mixture distribution with varying proportions of its components. In the following experiment, we explore the robustness of the Density Ratio Test in the face of this phenomenon.

More precisely, we consider $f^0$ as a mixture of two truncated Gaussians, denoted as $g_a$ and $g_b$, with covariance matrix $\begin{pmatrix} 1/100 & 0 \\ 0 & 1/100 \end{pmatrix}$ and means equal to (3/10, 6/10) and (6/10, 3/10), respectively. The distribution $f^1$ is chosen as in Setting 2: a truncated Gaussian with covariance matrix $\begin{pmatrix} 1/100 & 0 \\ 0 & 1/100 \end{pmatrix}$ and mean equal to (6/10, 6/10). We set the training sample size $n^0 + n^1$ to 1000000 with $n^0 = 0.7 \times (n^{train})$. We investigate the type I error of the test, as well as its power against alternatives $\theta = 0.015$. In the first scenario, we assume that at training time, $f^0 = 0.5 \times g_a + 0.5 \times g_b$, while in the test sample, $f^0 = \pi \times g_a + (1 - \pi) \times g_b$ for $\pi$ varying from 0.5 to 0.9. In the second scenario, we assume that at training time, $f^0 = \pi \times g_a + (1 - \pi) \times g_b$ for $\pi$ varying from 0.5 to 0.9, while in the test sample, $f^0 = 0.5 \times g_a + 0.5 \times g_b$. Each experiment is reproduced 300 times. The results are presented in Tables 1 and 2, respectively.

<table><caption>Table 1: Proportion of experiments where $H_0$ is rejected. The training sample $X^0$ has distribution $f^0 = 0.5 \times g_a + 0.5 \times g_b$, while for the test sample $f^0 = \pi \times g_a + (1 - \pi) \times g_b$.</caption><thead><tr><th>π</th><th>0.5</th><th>0.6</th><th>0.7</th><th>0.8</th><th>0.9</th></tr></thead><tbody><tr><td>Proportion of rejects under H<sub>0</sub></td><td>0.00</td><td>0.00</td><td>0.00</td><td>0.00</td><td>0.00</td></tr><tr><td>Proportion of rejects under H<sub>1</sub> with θ = 0.015</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr></tbody></table>

The results presented in Table 1 indicate a certain robustness of the Density Ratio Test against reasonable variations in the proportions of the components of the mixture distribution $f^0$. Indeed, the type I error remains lower than the desired level $\alpha = 0.05$ for all proportions considered in the first experiment, and as long as $\pi \ge 0.2$ in the second experiment. This should come as no surprise: the partition chosen by our algorithm favors bins where the density under $f^0$ is low, while the density under $f^1$ is relatively large. When such bins exist, they contain the majority of the signal and carry the most weight in the test, leading to rejection of the hypothesis when the number
<table><caption>Table 2: Proportion of experiments where $H_0$ is rejected. The training sample $X^0$ has distribution $f^0 = \pi \times g_a + (1 - \pi) \times g_b$, while for the test sample $f^0 = 0.5 \times g_a + 0.5 \times g_b$.</caption><thead><tr><th>π</th><th>0.5</th><th>0.6</th><th>0.7</th><th>0.8</th><th>0.9</th></tr></thead><tbody><tr><td>Proportion of rejects under H<sub>0</sub></td><td>0.00</td><td>0.00</td><td>0.00</td><td>0.00</td><td>1</td></tr><tr><td>Proportion of rejects under H<sub>1</sub> with θ = 0.015</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr></tbody></table>

of points falling into these bins is sufficiently large. On the contrary, the relative weight of the different regions with a large weight under $f^0$ can vary between the training and test times without significantly increasing the type I error, as these regions have a limited influence on the test result.

## B.2 Detection rate of Density Ratio Test, Bootstrap Density Ratio Test and Maximum Mean Discrepancy

In this section, we investigate the detection rate of the Density Ratio Test, the Bootstrap Density Ratio Test, and Maximum Mean Discrepancy. Figure 3 suggests that the detection threshold decreases more rapidly in the high signal setting than in the low signal setting. To confirm this intuition, we investigate the values of $\theta$ such that the Density Ratio Test has power between 0.15 and 0.85 for different training sample sizes. The corresponding values of the pairs $(n^{train}, \theta)$ are plotted on a logarithmic scale in Figure 6.

We consider the distributions $f^0$ and $f^1$ of Settings A, B and C, corresponding respectively to an easy, intermediate and hard contamination detection problem. We assume again that $n^0 = 0.7 \times (n^{train})$, and we let the number of training samples vary from 1000 to 1000000 (for DRT and BDRT) or to 100000 (for MMD, due to larger computation times). We then conduct test with a test sample size given by $n = 0.1 \times (n^{train})$. We simulate mixtures sampled from $(1 - \theta) \times f^0 + \theta f^1$ for $\theta$ varying between 0.0003 and 0.3. We investigate the values of $\theta$ such that the Density Ratio Test has power between 0.15 and 0.85 (for DRT) and between 0.3 and 0.7 (for BDRT and MMD) for different training sample sizes. The corresponding values of the pairs $(n^{train}, \theta)$ are plotted on a logarithmic scale in Figure 6.

Figure 6 reveals that the slope of the linear regression $\log(\theta) = a \log(1/n^{train}) + b$ is larger (in absolute value) in the high signal setting (Setting A): the detection threshold indeed decreases more rapidly in this case. More precisely, we note that the slope $a$ in Setting A is approximately $-0.97$: the test detects alternatives corresponding to approximately constant power at a rate close to $n^{-0.94}$ (up to a multiplicative constant). In this large signal setting, the Density Ratio Test almost achieves the fast detection rate $n^{-1}$. The slope $a$ in the intermediate setting is somewhat lower, approximately $-0.76$. By contrast, the slope is approximately $-0.65$ in the low signal setting. By contrast, the slope are respectively $-0.51, -0.52$, and $-0.5$ for the MMD test (in settings A, B, and C), and $-0.95, -0.76$, and $-0.7$ for BDRT.

## B.3 Analysis of the HIPC dataset

**Data pre-processing** We pre-process the observations so as to ensure that each measurement lies in the range $[0, 1]$. More precisely, we center each coordinates, and we apply an inverse sinus function. Finally, we rescale the result to the range $[0, 1]$.

**Experiment** We conduct the following experiment for each cell type, and each of the 62 samples. We consider the current sample of cells as the test sample, with the remaining 61 samples serving as training samples. Initially, we use 12 randomly selected samples (out of 61 samples) to determine
<table><caption>Table 2: Proportion of experiments where $H_0$ is rejected. The training sample $\mathcal{X}^0$ has distribution $f^0 = \pi \times g_a + (1 - \pi) \times g_b$, while for the test sample $f^0 = 0.5 \times g_a + 0.5 \times g_b$.</caption><thead><tr><th>π</th><th>0.5</th><th>0.6</th><th>0.7</th><th>0.8</th><th>0.9</th></tr></thead><tbody><tr><td>Proportion of rejects under H<sub>0</sub></td><td>0.00</td><td>0.00</td><td>0.00</td><td>0.00</td><td>1</td></tr><tr><td>Proportion of rejects under H<sub>1</sub> with θ = 0.015</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr></tbody></table>

of points falling into these bins is sufficiently large. On the contrary, the relative weight of the different regions with a large weight under $f^0$ can vary between the training and test times without significantly increasing the type I error, as these regions have a limited influence on the test result.

## B.2 Detection rate of Density Ratio Test, Bootstrap Density Ratio Test and Maximum Mean Discrepancy

In this section, we investigate the detection rate of the Density Ratio Test, the Bootstrap Density Ratio Test, and Maximum Mean Discrepancy. Figure 3 suggests that the detection threshold decreases more rapidly in the high signal setting than in the low signal setting. To confirm this intuition, we investigate the values of $\theta$ such that the Density Ratio Test has power between 0.15 and 0.85 for different training sample sizes. The corresponding values of the pairs $(n^{train}, \theta)$ are plotted on a logarithmic scale in Figure 6.

We consider the distributions $f^0$ and $f^1$ of Settings A, B and C, corresponding respectively to an easy, intermediate and hard contamination detection problem. We assume again that $n^0 = 0.7 \times (n^{train})$, and we let the number of training samples vary from 1000 to 1000000 (for DRT and BDRT) or to 100000 (for MMD, due to larger computation times). We then conduct test with a test sample size given by $n = 0.1 \times (n^{train})$. We simulate mixtures sampled from $(1 - \theta) \times f^0 + \theta f^1$ for $\theta$ varying between 0.0003 and 0.3. We investigate the values of $\theta$ such that the Density Ratio Test has power between 0.15 and 0.85 (for DRT) and between 0.3 and 0.7 (for BDRT and MMD) for different training sample sizes. The corresponding values of the pairs $(n^{train}, \theta)$ are plotted on a logarithmic scale in Figure 6.

Figure 6 reveals that the slope of the linear regression $\log(\theta) = a \log(1/n^{train}) + b$ is larger (in absolute value) in the high signal setting (Setting A): the detection threshold indeed decreases more rapidly in this case. More precisely, we note that the slope $a$ in Setting A is approximately $-0.97$: the test detects alternatives corresponding to approximately constant power at a rate close to $n^{-0.94}$ (up to a multiplicative constant). In this large signal setting, the Density Ratio Test almost achieves the fast detection rate $n^{-1}$. The slope $a$ in the intermediate setting is somewhat lower, approximately $-0.76$. By contrast, the slope is approximately $-0.65$ in the low signal setting. By contrast, the slope are respectively $-0.51, -0.52$, and $-0.5$ for the MMD test (in settings A, B, and C), and $-0.95, -0.76$, and $-0.7$ for BDRT.

## B.3 Analysis of the HIPC dataset

**Data pre-processing** We pre-process the observations so as to ensure that each measurement lies in the range $[0, 1]$. More precisely, we center each coordinates, and we apply an inverse sinus function. Finally, we rescale the result to the range $[0, 1]$.

**Experiment** We conduct the following experiment for each cell type, and each of the 62 samples. We consider the current sample of cells as the test sample, with the remaining 61 samples serving as training samples. Initially, we use 12 randomly selected samples (out of 61 samples) to determine
<figure><img src="image_8.png" /><figcaption>Figure 6: Values of pairs $(n^{\text{train}}, \theta)$ such that the Bootstrap Density Ratio Test (left) and MMD Test (right) have empirical power between 0.15 and 0.85 for DRT, and between 0.3 and 0.7 for BDRT and MMD for an alternative parameterized by $\theta$ when the training sample size is $n^0 + n^1$, plotted on a logarithmic scale. The color corresponds to the empirical power, the shape of the dots to the setting of the experiment (low, intermediate or high signal).</figcaption></figure>

the partition. Subsequently, we calibrate the Bootstrap Density Ratio Test to achieve a desired significance level $\alpha$ with a type one error of 5%. This involves estimating the distribution of the statistic under the null hypothesis using 25 samples (excluding all cells labeled “c”) and applying the test on the remaining 24 samples (also excluding all cells labeled “c”). We choose $\alpha$ as the largest value that ensures the test declares at most one false positive.

Finally, we execute our test for various prevalence levels $\theta$ of cell type *c*. To achieve this, we re-estimate the distribution of the test statistic under the null hypothesis using the same 49 samples used for calibration. Subsequently, we generate a synthetic test sample with a sample size of 10 000 cells, and with varying prevalence levels $\theta$ for cell type *c*. This is done by randomly selecting the corresponding number of cells of type *c* and cells of other types (without replacement if the number is smaller than the actual count, with replacement otherwise). For each prevalence level $\theta$, we repeat this sampling process 10 times. Averaging across the 62 samples, we obtain an estimate of the test's power for detecting each of the three cell types against alternatives characterized by varying levels of prevalence $\theta$.

We proceed similarly to estimate the power of MMD.
<figure><img src="image_8.png" /><figcaption>Figure 6: Values of pairs $(n^{\text{train}}, \theta)$ such that the Bootstrap Density Ratio Test (left) and MMD Test (right) have empirical power between 0.15 and 0.85 for DRT, and between 0.3 and 0.7 for BDRT and MMD for an alternative parameterized by $\theta$ when the training sample size is $n^0 + n^1$, plotted on a logarithmic scale. The color corresponds to the empirical power, the shape of the dots to the setting of the experiment (low, intermediate or high signal).</figcaption></figure>

the partition. Subsequently, we calibrate the Bootstrap Density Ratio Test to achieve a desired significance level $\alpha$ with a type one error of 5%. This involves estimating the distribution of the statistic under the null hypothesis using 25 samples (excluding all cells labeled "c") and applying the test on the remaining 24 samples (also excluding all cells labeled "c"). We choose $\alpha$ as the largest value that ensures the test declares at most one false positive.

Finally, we execute our test for various prevalence levels $\theta$ of cell type c. To achieve this, we re-estimate the distribution of the test statistic under the null hypothesis using the same 49 samples used for calibration. Subsequently, we generate a synthetic test sample with a sample size of 10 000 cells, and with varying prevalence levels $\theta$ for cell type c. This is done by randomly selecting the corresponding number of cells of type c and cells of other types (without replacement if the number is smaller than the actual count, with replacement otherwise). For each prevalence level $\theta$, we repeat this sampling process 10 times. Averaging across the 62 samples, we obtain an estimate of the test's power for detecting each of the three cell types against alternatives characterized by varying levels of prevalence $\theta$.

We proceed similarly to estimate the power of MMD.