Kernel density estimation is a method of estimating the probability distribution of a random variable based on a random sample. In contrast to a histogram, kernel density estimation produces a smooth estimate. The smoothness can be tuned via the kernel’s bandwidth parameter. With the correct choice of bandwidth, important features of the distribution can be seen, while an incorrect choice results in undersmoothing or oversmoothing and obscured features.
This example shows a histogram and a kernel density estimation for times between eruptions of Old Faithful Geyser in Yellowstone National Park, taken from R’s faithful
dataset. The data follow a bimodal distribution; short eruptions are followed by a wait time averaging about 55 minutes, and long eruptions by a wait time averaging about 80 minutes. In recent years, wait times have been increasing, possibly due to the effects of earthquakes on the geyser’s geohydrology.
This example is based on a Protovis version by John Firebaugh. See also a two-dimensional density estimation of this dataset using d3-contour.
@Abhilash-Chandran
svg
is referring to the<svg width="960" height="500"></svg>
element and.attr
gets the specified attribute on the element, sosvg.attr("width")
gets the width attribute that was specified on the element (in this case960
). It looks like.attr
will either always return a string or just may return a string in some instances, so the+
unary operator is used to coerce the value to a number. If you try this yourself in a console, you should see something like the following:So to summarize, it's getting the width and the height of the HTML element and ensuring they're numeric.