3
$\begingroup$

I'm using R, but the density function requires the actual samples, but I only have the histogram data. Can I still use kernel density estimation, or is there a better tool for this?

$\endgroup$
  • 3
    $\begingroup$ If you made some assumptions about how the data were distributed within the bins, perhaps. $\endgroup$ – Glen_b Jul 12 '13 at 2:56
2
$\begingroup$

Beyond the specific implementation question, I am not sure to understand how you would go about it. In a sense, an histogram is already a sort of “smoother”. You could make it look a little more “curved” but much information has already been lost and the artifacts created by the bins' location and width cannot be reversed without strong assumptions.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks for the clarification. I can get something reasonable by assuming the points are generated uniformly within each bin, generating these points (since I have the original n), and then passing this data to the density() function. I'm not sure if this is better than just smoothing the histograms by using splines or some other approach. $\endgroup$ – reisner Jul 12 '13 at 18:01
  • $\begingroup$ An explanation about the down vote could warn unsuspecting readers (and the clueless author) about what is wrong with this answer… $\endgroup$ – Gala Jul 14 '13 at 18:01
2
$\begingroup$

Kernel density estimation in the most common forms requires the raw data. Your problem seems more on the line of finite volume methods. However it can also be approached in a simpler way in the "spirit" of KDE. Set up a parametric basis of (smooth) "kernels" centered at each bin, e.g. 3 bins wide so that the 2 neighbours are covered in each case. Then build a system of equations representing the N constraints given by the histogram bins counts. These can be expressed as the integral of the parametric PDF over each bin. So you get a system of linear equations. It will be underdetermined because of missing boundary conditions, which you might want to impose additionally or trade for other constraints.

I would not call these "strong" assumptions (although they imply a little bias, but so do histograms already), and even though some information had been lost by binning there is still enough to improve on plain histograms. Note that because of that information loss the solution that you'll obtain will be worse than just using the same parametric basis on the raw data.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ What's the point of the whole thing? $\endgroup$ – Gala Jul 14 '13 at 17:57
  • $\begingroup$ Improving smoothness over plain histograms while using KDE-like methods and histogram data only. Admittedly some bias is introduced, but other bias is removed, so the outcome is positive in most reasonable cases (as a function of samples/bins). Apparently the answer was not clear enough, but to improve it I would need more specific hints: is the procedure itself not well-explained or its context? $\endgroup$ – Quartz Jul 29 '13 at 10:58
  • $\begingroup$ I am still not sure I understand how you could “remove bias” without substantial assumptions. Admittedly, my theoretical understanding is limited but intuitively, all the damage is done by the histogram, I don't see how merely making it look smoother after the fact is worth much effort. Many (most?) misleading histograms would still be just as misleading, perhaps with the added drawback of a false sense of safety. $\endgroup$ – Gala Jul 29 '13 at 11:18
  • $\begingroup$ Thanks a lot for that really nice example! Mind that those are issues appearing with low sample/bins ratios, which pose additional problems. I am just pointing to the simpler large ratios setting for clarity. Histograms impose a peculiar structure and thus bias over the real PDF: imagine a thin peak centered in the middle of a bin, a piecewise constant approximation will be smaller in the middle and larger at the edges now matter how many samples you get. Working in a different space by definition can avoid such artifacts altogether (and that would be e.g. KDE or kernel-pseudohistograms). $\endgroup$ – Quartz Jul 29 '13 at 11:55
  • $\begingroup$ However now we're somewhat making a compromise between the two worlds using data from the first and using it in the second and you're right that it's tricky. But intuition merges the binning (our information) and reconstruction (histogram/piecewise constant) into a single step, I'm just trying to say that the binning information can be successfully projected on a better space. However to make this clear full details are needed, I can prepare a short note on that. $\endgroup$ – Quartz Jul 29 '13 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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