# HG changeset patch
# User Marshall Hampton <hamptonio@gmail.com>
# Date 1242596893 18000
# Node ID 433e36b523625c380addbfc3ad5ab19c7471e841
# Parent 7f9164053b2a6e9302193d8a3c710b826c6041cf
Baby step towards toplevel statistics functionality.
diff r 7f9164053b2a r 433e36b52362 sage/stats/all.py
a

b


1  1  from r import (ttest) 
2  2  
3  3  import hmm.all as hmm 
 4  from basic_stats import mean, variance, std 
 5  
diff r 7f9164053b2a r 433e36b52362 sage/stats/basic_stats.py


+


 1  """ 
 2  Basic statistics. 
 3  
 4  This module aims to provide some of the most basic and commonlyneeded 
 5  statistics functionality at the top import level. 
 6  
 7  AUTHOR: 
 8   Marshall Hampton, first version, 2009 
 9  """ 
 10  
 11  from sage.calculus.calculus import sqrt 
 12  
 13  def mean(a_list): 
 14  """ 
 15  Returns the mean of a list of objects if possible. 
 16  
 17  EXAMPLES: 
 18  sage: mean([1,2,3]) 
 19  2 
 20  """ 
 21  sum = 0 
 22  for q in a_list: 
 23  sum = sum + q 
 24  return sum/len(a_list) 
 25  
 26  def variance(a_list): 
 27  """ 
 28  Returns the population variance of a list. 
 29  
 30  EXAMPLES: 
 31  sage: variance([0,2,2,4]) 
 32  2 
 33  """ 
 34  m = mean(a_list) 
 35  out = 0 
 36  for q in a_list: 
 37  out = out + (qm)**2 
 38  return out/len(a_list) 
 39  
 40  def std(a_list): 
 41  """ 
 42  Returns the population standard deviation of a list. 
 43  
 44  EXAMPLES: 
 45  sage: std([1,2,3]) 
 46  sqrt(2)/sqrt(3) 
 47  """ 
 48  return sqrt(variance(a_list)) 