Default violin bandwidth misnamed: should be Scott's, not Silverman's
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 18.3k
- Forks
- 2k
- Ø Merge
- 2 T. 12 Std.
- Gemergte PRs (30 T.)
- 28
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne in src/traces/violin/calc.js bei der Funktion silvermanRule und überprüfe den Referenzeintrag zur Violin-Bandbreite unter plotly.com/javascript/reference/#violin-bandwidth. Überprüfe, dass die Formel 1.059 Scotts Regel ist, und aktualisiere anschließend die Namen der Funktion und der Dokumentation konsistent. Erledigt ist dies, wenn der Codekommentar, der Funktionsname und der Referenztext sämtlich Scott's rule nennen, ohne die Berechnung zu ändern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript
- Bereich
- data-visualization, documentation
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 56/100