plotly / plotly/plotly.js

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

Ouverte
#4,820 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

bug P3
Langage dominant
JavaScript
Étoiles
18.3k
Forks
2k
Merge moyen
2 j 12 h
PR mergées (30 j)
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.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez dans src/traces/violin/calc.js, au niveau de la fonction silvermanRule, et examinez l’entrée de référence de la largeur de bande du violin sur plotly.com/javascript/reference/#violin-bandwidth. Vérifiez que la formule 1.059 est la règle de Scott, puis mettez à jour les noms de la fonction et de la documentation de manière cohérente. Le travail est terminé lorsque le commentaire du code, le nom de la fonction et le texte de référence identifient tous Scott's rule sans modifier le calcul.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript
Domaine
data-visualization, documentation
Type d'issue
Bug
Difficulté
2/5
Temps estimé
1-3 heures
Activité
À l'abandon
Clarté
Clairement spécifiée
Accessibilité débutants
56/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.