plotly / plotly/plotly.js

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

Abierto
#4,820 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

bug P3
Lenguaje dominante
JavaScript
Estrellas
18.3k
Forks
2k
Merge medio
2 d 12 h
PR fusionados (30 d)
28

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza en src/traces/violin/calc.js, en la función silvermanRule, y revisa la entrada de referencia del ancho de banda del violin en plotly.com/javascript/reference/#violin-bandwidth. Verifica que la fórmula 1.059 corresponde a Scott's rule y, a continuación, actualiza de forma coherente los nombres de la función y de la documentación. Se considera terminado cuando el comentario del código, el nombre de la función y el texto de referencia identifican todos Scott's rule sin cambiar el cálculo.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript
Área
data-visualization, documentation
Tipo de issue
Error
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
56/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.