6
$\begingroup$

In R, the function skewness from package moments allows one to calculate the skewness of the distribution from a given sample. Does anybody know if there is a ready-to-use function to calculate the skewness of the distribution from a given histogram?

$\endgroup$
2
  • $\begingroup$ Not sure I understand the question... If you have an histogram object, you should normally have access to the data from which this object was constructed. This is given by the $xname attribute of the histogram object. $\endgroup$ Jul 12, 2011 at 0:40
  • 4
    $\begingroup$ @dominic Frequently--especially when reading papers--a histogram is just about the most detailed presentation of the data available. This situation is not new: older statistical texts spend a lot of time on making estimates from histograms and binned data. For instance, see the MathWorld article on Sheppard's Corrections and note the dates of the references. $\endgroup$
    – whuber
    Jul 12, 2011 at 0:59

2 Answers 2

5
$\begingroup$

Sounds like you're looking at a published histogram and don't have the actual data?

If that is the case you could calculate a rough skewness figure by doing something like pub_his <- c(rep(10,16),rep(15,18),rep(20,27)...), picking the mid point of each bar and reading the frequency off the graph, then you'd have the data and could use the skewness function.

$\endgroup$
4
  • $\begingroup$ This would be approximate though, but probably just as useful as an accurate skewness value.... $\endgroup$
    – nzcoops
    Jul 12, 2011 at 1:02
  • 2
    $\begingroup$ @nz You're right. This method is great for estimating the third moment when the skewness is small. However, because it tends to overestimate the variance, it will typically underestimate the absolute value of the skewness. The correction depends on the size of the histogram bin width relative to the standard deviation (as well as on the shape of the distribution): it becomes substantial when the bin widths exceed 1 SD (which can happen for coarse histograms of highly skewed datasets). $\endgroup$
    – whuber
    Jul 12, 2011 at 1:13
  • $\begingroup$ @nzcoops: Yes, I can do it this way. So, no way to calculate $\sum (x_i - \bar{x})^2$ and $\sum (x_i - \bar{x})^3$ knowing bar positions and heights without "re-generating" the data from the histogram? $\endgroup$
    – Leo
    Jul 12, 2011 at 2:40
  • 1
    $\begingroup$ Correct, without the xis you can't do any calculations that include the xis. You could substitute your 'middle of the bin' position and get an approximate result, but personally I would never do that and I wouldn't recommend it to you either. As whuber notes, there is lots at play here, bin with etc. If this is a histgram in a journal article try contacting the authors, you may be pleasantly surprised. $\endgroup$
    – nzcoops
    Jul 12, 2011 at 2:55
5
$\begingroup$

In the case of variance (and indeed for the fourth central moment), the "taking the bin center" approach carries a bias.

Such bias can be corrected, via what are known as Sheppard's correction e.g. see here, which in the case of variance would subtract $\frac{1}{12}$ of the square of the bin-width from the binned estimate of the second moment. However, in the case of the third moment, no such adjustment is needed.

On the other hand, the third-moment-skewness, if just calculated directly by dividing the binned third-moment by the unadjusted binned-variance to the power $\frac{3}{2}$ will yield too large a denominator, and so the skewness will be on average slightly underestimated.

This suggests that the binned variance be adjusted by Sheppard's correction before computing the skewness. So:

1) calculate the binned moments (first, second, third) as needed (i.e. by taking every observation at its bin center and if possible using the weighted/grouped-data formulas)

2) correct the variance for the grouping bias

3) compute the skewness by dividing the grouped third moment by the corrected grouped second moment.

However, you may want to ponder the circumstances under which the corrections apply. For example, you might see the discussion of the corrections in Kendall and Stuart, or maybe consult

M. G. Kendall (1938),
The Conditions under which Sheppard's Corrections are Valid
Journal of the Royal Statistical Society,
Vol. 101, No. 3, p592-605

[Even so, dividing an unbiased numerator by an unbiased denominator doesn't itself lead to an unbiased ratio, even when they're independent, so if an actually unbiased ratio is of interest, further analysis would be needed -- but we don't generally concern ourselves with that when dealing with ordinary sample skewness either.]

$\endgroup$

Your Answer

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

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