Default violin bandwidth misnamed: should be Scott's, not Silverman's
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 18.3k
- 派生
- 2k
- 平均合并
- 2 天 12 小时
- 30 天内合并 PR
- 28
描述
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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 src/traces/violin/calc.js 中的 silvermanRule 函数开始,检查 plotly.com/javascript/reference/#violin-bandwidth 中关于 violin 带宽的参考条目。确认 1.059 公式是 Scott's rule,然后一致地更新函数名称和文档名称。完成的标准是:代码注释、函数名称和参考文本都标明 Scott's rule,同时不改变计算过程。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript
- 领域
- data-visualization, documentation
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 56/100