Opened 11 years ago

Closed 10 years ago

#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: Merged in: sage-4.7.alpha5
Authors: Andrew Hou, Benjamin Jones Reviewers: Simon Spicer
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

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 (2)

trac_9028_stats.patch (648 bytes) - added by amhou 11 years ago.
trac_9028_stats_fix+example.patch (1.2 KB) - added by benjaminfjones 10 years ago.
fix plus an example to test it

Download all attachments as: .zip

Change History (12)

Changed 11 years ago by amhou

comment:1 Changed 11 years ago by was

  • Status changed from new to needs_review

comment:2 Changed 11 years ago by was

  • Status changed from needs_review to positive_review

comment:3 Changed 11 years ago by was

  • Status changed from positive_review to needs_work

comment:4 Changed 11 years ago by was

Please add a new example to the docstring that illustrates that this bug has been fixed.

Changed 10 years ago by benjaminfjones

fix plus an example to test it

comment:5 follow-up: Changed 10 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:6 Changed 10 years ago by benjaminfjones

  • Status changed from needs_work to needs_review

comment:7 in reply to: ↑ 5 Changed 10 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 10 years ago by spice

  • Keywords standard deviation added
  • Milestone set to sage-4.7
  • Reviewers set to Simon Spicer
  • Status changed from needs_review to positive_review

All good (reviewed trac_9028_stats_fix+example.patch; trac_9028_stats.patch is obsolete).

comment:9 Changed 10 years ago by benjaminfjones

  • Authors changed from Andrew Hou to Andrew Hou, Benjamin Jones

comment:10 Changed 10 years ago by jdemeyer

  • Merged in set to sage-4.7.alpha5
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.