5
$\begingroup$

I have several histograms which I would like to compare to one reference histogram to see which one is the most similar to the reference in terms of the shape of the distribution.

Kologorov-Smirnov gives unhelpful answers as often the largest difference in y-value is not indicative of worst fit. From inspection-by-eye, the shape of some this method says to be the worst fit are actually the most similar in shape, but with the distribution shifted up or down the x-axis.

Chi squared: not sure how I'd implement this as my data are continuous (continuous numerical data on x-axis, frequency of these, binned, on y-axis), so offput by the fact that the number of bins I arbitrarily choose to include has such a large effect, and don't know about degrees of freedom.

I don't need a good P-value, just to know qualitatively which of a variety of histograms are most similar to an initial histogram. None of the histograms follow a normal distribution or an approximation of a normal distribution.

From reading, the Bhattacharyya distance seems like a good way of getting what I am looking for, but I don't know how to get this from my excel histograms and data.

A description of how someone with excel and very limited matlab skills might compute bhattacharyya distance, or any other suggestions of how to qualitatively say which of several histograms is most similar in terms of shape to a reference histogram would be greatly appreciated.

$\endgroup$
5
  • $\begingroup$ This is answered here although the question is different. Probabilistic separability measures in R separability.measures <- function ( Vector.1 , Vector.2 ) { # convert vectors to matrices in case they are not Matrix.1 <- as.matrix (Vector.1) Matrix.2 <- as.matrix (Vector.2) # define means mean.Matrix.1 <- mean ( Matrix.1 ) mean.Matrix.2 <- mean ( Matrix.2 ) # define difference of means mean.difference <- mean.Matrix.1 - mean.Matrix.2 # define covariances for supplied matrices cv.Matrix.1 <- cov ( Matrix.1 ) $\endgroup$
    – JEquihua
    Jan 10, 2014 at 22:54
  • $\begingroup$ Because the full code appears elsewhere and this does not address the request for Excel or Matlab solutions, it really ought to be posted as a comment rather than an answer. If you were to replace the code by an explanation of its construction that would allow for porting to other platforms it would make a fine answer. $\endgroup$
    – whuber
    Jan 10, 2014 at 23:04
  • $\begingroup$ It might be nice to post a couple of these histograms for people to see, if you can. $\endgroup$ Jan 10, 2014 at 23:25
  • 1
    $\begingroup$ Bhattacharya distance would suffer from the same issue as K-S - it will indicate a discrepancy when there's just a shift. $\endgroup$
    – Glen_b
    Jan 11, 2014 at 3:59
  • $\begingroup$ Thank you. I said R would be okay in the question title because I do have access to R, and if no-one knew a way of doing this in the other two formats, I am willing to try to start from scratch with R to get this done. The code looks helpful: if someone could tell me similar in matlab or excel, or tell me how I would get my data into R in a format which would work with this code I would be really grateful. $\endgroup$ Jan 11, 2014 at 12:00

1 Answer 1

3
$\begingroup$

Use the fpc package: https://cran.r-project.org/web/packages/fpc/fpc.pdf

library(fpc)
bhattacharyya.dist(mu1, mu2, covarianceMatrix, covarianceMatrix2)

Can use cov to help calculate covariance.

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.