bias in random.normalvariate??

Steve Holden steve at holdenweb.com
Sat Aug 4 09:12:23 EDT 2007


Robert Kern wrote:
> drewlist at gmail.com wrote:
>> I'm a Python newbie and certainly no expert on statistics, but my wife
>> was taking a statistics course this summer and to illustrate that
>> sampling random numbers from a distribution and taking an average of
>> the samples gives you a random number as the result (bigger sample ->
>> smaller variance in the calculated random number, converging in on the
>> mean of the original distribution), I threw together this program:
>>
>> #! /usr/bin/python
>>
>> import random;
>>
>> i=1
>> samplen=100
>> mean=130
>> lo=mean
>> hi=mean
>> sd=10
>> sum=0
>> while(i<=samplen):
>> 	x=random.normalvariate(mean,sd)
>> 	#print x
>> 	if x<lo: lo=x
>> 	if x>hi: high=x
>> 	sum+=x
>> 	i+=1
>> print 'sample mean=', sum/samplen, '\n'
>> print 'low value =', lo
>> print 'high value=', high
> 
> Your code has an error. In the middle of your code, you changed "hi" to "high".
> 
Which very nicely makes the point that you can test algorithms driven by 
random data using statistical functions on the output!

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd           http://www.holdenweb.com
Skype: holdenweb      http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------




More information about the Python-list mailing list