I would like to obtain the ratio between two distribution densities and I wonder whether there is some well-founded and established approach to do that.
Let's say that I have two samples for the random variable $X$ coming from two populations, $P_1$ and $P_2$, that are likely to be distributed differently across the valid range of $X$.
Then I'll like to at least approximate the function $f(X)$ of the ratio between the densities in both populations across the range of $X$.
What I am currently doing in R is to estimate the density of each sample using kernel density estimation (
density() function). Then I can approximate $f(X)$ for any given value by interpolating the closest point estimates returned by
density() on each sample and dividing the resulting values.
Although this is satisfactory to some extent I wonder whether there is a better way. Specially, if there is an existing implementation in R. For example, I am afraid that the ratio could be extremely variable in regions where one or both distributions have very low density and I wonder whether there is a method to also obtain some estimate of uncertainty.