plotly / plotly/plotly.js

Default violin bandwidth misnamed: should be Scott's, not Silverman's

Aperta
#4,820 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug P3
Lingua principale
JavaScript
Stelle
18.3k
Fork
2k
Merge medio
2g 12h
PR unite (30g)
28

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia in src/traces/violin/calc.js, nella funzione silvermanRule, e rivedi la voce di riferimento per la bandwidth del violin all’indirizzo plotly.com/javascript/reference/#violin-bandwidth. Verifica che la formula 1.059 sia Scott's rule, quindi aggiorna in modo coerente i nomi della funzione e della documentazione. Il lavoro è completato quando il commento nel codice, il nome della funzione e il testo di riferimento identificano tutti Scott's rule senza modificare il calcolo.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript
Ambito
data-visualization, documentation
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
56/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.