This paper deals with the classical statistical problem of comparing the probability distributions of two real random variables $X$ and $X_0$, from a double independent sample. While most of the usual tools are based on the cumulative distribution function $F$ and $F_0$ of the variables, we focus on the relative density, a function recently used in two-sample problems, and defined as the density of the variable $F_0(X)$. We provide a nonparametric adaptive strategy to estimate the target function. We first define a collection of estimates using a projection on the trigonometric basis and a preliminar estimator of $F_0$.
An estimator is selected among this collection of projection estimates, with a criterion in the spirit of the Goldenshluger-Lepski methodology. We show the optimality of the procedure both in the oracle and the minimax sense: the convergence rate for the risk computed from an oracle inequality matches with the lower bound, that we also derived. Finally, some simulations illustrate the method.