# Ratio between two densities

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

$$f(x)=\frac{Density(x|P_1)}{Density(x|P_2)}$$

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.

-
Could you explain what you will be doing with this ratio estimate? What conclusions do you hope to draw from it? –  whuber Oct 1 '12 at 14:37
I want to show for what values of x one distribution is enriched/bias versus the other. Also would be nice if I can test the significance of differences (ratio != 1) in different regions in x. –  Valentin Ruano Oct 1 '12 at 15:03
OK, that's a reasonable and interesting goal. But I'm still wondering whether it's just an intermediate step towards some more fundamental determination. Could you share with us some information about your data and what you're trying to learn from them? This might suggest approaches that give you better solutions to whatever problem it is that really interests you. The risk here is that even a great solution to the question as stated might lead to an inferior solution to your main problem. (Distribution ratios are hard to estimate and notoriously unstable.) –  whuber Oct 1 '12 at 15:07
... However this might well not be the case for different reasons such as biases in the sequencing process due to the chemistry involved, actual genomic changes in the specimen as compared to the reference, limitations in the algorithm used for mapping these short fragment to the reference... So one thing that we want to investigate is the reference coverage bias introduced at different steps of the process versus some properties of these short DNA fragments, the random x variable. A notorious example is the G+C nucleotide content of the fragment. –  Valentin Ruano Oct 1 '12 at 18:02
If you are just interested in a summary statistic like bias you may not need the detail that you get by comparing densities. Also why the ratio of the densities rather than say the difference? I at first thought that maybe you had a classification problem where the Bayes rule would have a boundary where the ratio of densities is 1. Then the ratio would clearly be of interest and if a nonparametric approach was needed kernel density estimates might be used to estimate the ratio. So Bill Huber was wise to question you on the application. –  Michael Chernick Oct 1 '12 at 18:49