Default violin bandwidth misnamed: should be Scott's, not Silverman's
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 18.3k
- Forks
- 2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 28
Description
There seems to be a naming bug in code and reference documentation for violin plots. What is referred to as "Silverman's rule of thumb" seems to actually be "Scott's rule of thumb" -- a slight variant of Silverman's.
Replacing two strings seems like it would fix this incorrect name.
Bug in code
Code at src/traces/violin/calc.js#L99 notes:
// Default to Silveman's rule of thumb
// - https://stats.stackexchange.com/a/6671
// - https://en.wikipedia.org/wiki/Kernel_density_estimation#A_rule-of-thumb_bandwidth_estimator
// - https://github.com/statsmodels/statsmodels/blob/master/statsmodels/nonparametric/bandwidths.py
function silvermanRule(len, ssd, iqr) {
var a = Math.min(ssd, iqr / 1.349);
return 1.059 * a * Math.pow(len, -0.2);
}
Bug in docs
Likewise, reference documentation at https://plotly.com/javascript/reference/#violin-bandwidth notes:
bandwidth
Parent: data[type=violin]
Type: number greater than or equal to 0
Sets the bandwidth used to compute the kernel density estimate. By default, the bandwidth is
determined by Silverman's rule of thumb.
The inconsistency
Code comments referenced above link to https://github.com/statsmodels/statsmodels/blob/master/statsmodels/nonparametric/bandwidths.py, which includes these excerpts:
def bw_scott(x, kernel=None):
"""
Scott's Rule of Thumb
...
"""
...
return 1.059 * A * n ** (-0.2)
def bw_silverman(x, kernel=None):
"""
Silverman's Rule of Thumb
...
"""
...
return .9 * A * n ** (-0.2)
Scott's uses 1.059 where Silverman's uses 0.9. Scott's is the more common default bandwidth -- see e.g. https://stat.ethz.ch/R-manual/R-devel/library/stats/html/bandwidth.html.
So the calc.js function gets the implementation right, but uses the incorrect name. It uses 1.059 but incorrectly calls it Silverman's, when it should be Scott's per above.
So it seems the function name should be scottRule (or at least not silvermanRule), and the docs should be updated accordingly.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/traces/violin/calc.js at the silvermanRule function and review the violin bandwidth reference entry at plotly.com/javascript/reference/#violin-bandwidth. Verify that the 1.059 formula is Scott's rule, then update the function and documentation names consistently. Done means the code comment, function name, and reference text all identify Scott's rule without changing the calculation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- data-visualization, documentation
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 56/100