3
$\begingroup$

Consider this (R) data:

nd1 <- rnorm(100)
nd2 <- rnorm(100)
pd1 <- rpois(100, 2)
pd2 <- rpois(100, 2)

I want to define two functions - f1 and f2:

f1 <- function(vec) {...}
f2 <- function(vec1, vec2) {...}

f1 should return a list of pairs: standard dist name, similarity value. For example:

# returns 
f1(nd1) 
normal 0.9
poisson 0.1
...
f1(pd1) 
normal 0.1
poisson 0.9
...

f2 should return a number that shows how similar two distributions are to each other, in terms of the standard distributions:

f2(nd1, nd2) # high value, say, 0.9 (because both are random normal distributions)
f2(nd1, pd1) # low value, say, 0.1
f2(pd1, pd2) # high value, say, 0.9

How do I implement these functions f1 and f2? Are there pre-built functions in R that can do this?

I saw this other question that mentions the Kullback–Leibler divergence, but not sure if that can be used to define these functions.

$\endgroup$
6
  • 3
    $\begingroup$ The Kolmogorov distance is a standard metric that measures the distance between distributions, so that's one possibility. But your question is how close a given distribution is to an entire class of distributions, which basically means finding the distance between the distribution and the closest member within that class. So you would need some way of identifying this "closest" distribution based on your chosen metric. $\endgroup$
    – dsaxton
    Commented Sep 15, 2016 at 14:13
  • 1
    $\begingroup$ @dsaxton is right. I would like to add another caveat: any metric of "closeness" also ought to account for the dimension of the distribution family. For instance, the Normal family requires two parameters, but the Poisson only one, so the Normal family is a little more "flexible" and therefore should be penalized a bit in the comparison. BTW, how you frame and pursue your question really ought to account for why you are writing this code: what decisions or actions will be taken as a consequence of its output? $\endgroup$
    – whuber
    Commented Sep 15, 2016 at 14:55
  • $\begingroup$ You could maybe consider starting with visualization methods? One alternative is studying the relative distribution (relative to your list of candidate distributions). See my answer here: stats.stackexchange.com/questions/126388/… $\endgroup$ Commented Sep 15, 2016 at 15:01
  • $\begingroup$ @dsaxton - I realize that the question needs to be formulated better, still not sure how :-) $\endgroup$
    – Anand
    Commented Sep 15, 2016 at 15:15
  • $\begingroup$ @whuber - the primary motivation is that there are some algorithms that assume certain distributions, and I want to look at my data, and determine how close it is, say, to a random normal distribution. I could visualize it, of course, but I think an actual metric allows me to automate that part. $\endgroup$
    – Anand
    Commented Sep 15, 2016 at 15:19

0

Your Answer

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

Browse other questions tagged or ask your own question.