Ticket #9028 (closed defect: fixed)
Basic Stats - Standard Deviation
| Reported by: | amhou | Owned by: | amhou |
|---|---|---|---|
| Priority: | minor | Milestone: | sage-4.7 |
| Component: | statistics | Keywords: | standard deviation |
| Cc: | Work issues: | ||
| Report Upstream: | N/A | Reviewers: | Simon Spicer |
| Authors: | Andrew Hou, Benjamin Jones | Merged in: | sage-4.7.alpha5 |
| Dependencies: | Stopgaps: |
Description
Fixes the calculation of standard deviation.
Previously, sample standard deviation had returned a denominator of n, this fix gives a denominator of n-1.
Attachments
Change History
comment:4 Changed 3 years ago by was
Please add a new example to the docstring that illustrates that this bug has been fixed.
Changed 2 years ago by benjaminfjones
-
attachment
trac_9028_stats_fix+example.patch
added
fix plus an example to test it
comment:5 follow-up: ↓ 7 Changed 2 years ago by benjaminfjones
I've attached a new patch witch includes the fix plus an example to test the affected block of code. I couldn't think of a better way to access the block than to define a toy class that has its own mean() function which returns a Python long. If the mean() function from basic_stats.py has to be called, the type of 'x' at line 289 won't ever be 'int' or 'long' so the code block in question is never reached.
Maybe someone can suggest a better example?
Here is a before / after log to show that the fix works and that the example tests it.
sage: R = SillyPythonList() sage: list(R) [2L, 4L] sage: len(R) 2 sage: mean(R) 3L sage: variance(R) 1 sage: variance(R, bias=True) 1 sage: R = [2,4] sage: mean(R) 3 sage: variance(R) 2 sage: variance(R,bias=True) 1 ### LOG (after patch) sage: R=SillyPythonList() sage: len(R) 2 sage: mean(R) 3L sage: variance(R) 2 sage: variance(R, bias=True) 1 sage: R = [2,4] sage: variance(R) 2 sage: variance(R, bias=True) 1
comment:7 in reply to: ↑ 5 Changed 2 years ago by benjaminfjones
Replying to benjaminfjones:
... and I made sure the doctest passes for the new example. I'm applying the patch to Sage Version 4.6.1.alpha1.
comment:8 Changed 2 years ago by spice
- Keywords standard deviation added
- Reviewers set to Simon Spicer
- Status changed from needs_review to positive_review
- Milestone set to sage-4.7
All good (reviewed trac_9028_stats_fix+example.patch; trac_9028_stats.patch is obsolete).
comment:9 Changed 2 years ago by benjaminfjones
- Authors changed from Andrew Hou to Andrew Hou, Benjamin Jones
comment:10 Changed 2 years ago by jdemeyer
- Status changed from positive_review to closed
- Resolution set to fixed
- Merged in set to sage-4.7.alpha5
