## GIStemp STEP1_listStats

### The Python program listStats.py

Here is the listing. The explanation will follow some months or weeks from now below, after the === bar.

```"""
list oriented functions for computation
of statistical information.
"""

import math

length = len(list)
if not start: start = 0
if not stop: stop = length
sum = wgt = 0
for i in range(start, stop):
datum = list[i]
sum = sum + datum
wgt = wgt + 1
if wgt == 0: return bad
return sum / wgt

length = len(list)
for i in range(length):
datum = list[i]
result[i] = datum - mean
return result

def sigma(list, mean, start=None, stop=None, bad=-999.0):
length = len(list)
if not start: start = 0
if not stop: stop = length
s2 = n = 0
for i in range(start, stop):
datum = list[i]
n = n + 1
s2 = s2 + pow(datum - mean, 2)
if n == 0: return bad
variance = s2 / n
sigma = pow(variance, 0.5)
return sigma

length = len(list)
if not start: start = 0
if not stop: stop = length
sos = sum = wgt = 0
for i in range(start, stop):
x = list[i]
sos = sos + x * x
sum = sum + x
wgt = wgt + 1
if wgt == 0:
else:
mean = sum / wgt
sigma = math.sqrt(sos / wgt - mean * mean)
return mean, sigma

return (x - mean) / sigma
return map(f, list)

else: return x - mean
return map(f, list)

length = len(list)
n = 0
Sx = Sx2 = Sxy = Sy = 0.0
for i in range(length):
y = list[i]
x = float(i)
n = n + 1
Sx = Sx + x
Sx2 = Sx2 + x*x
Sxy = Sxy + x*y
Sy = Sy + y
m = Sxy - (Sx / n) * Sy
m = m / (Sx2 - (Sx / n) * Sx)
b = (Sy - Sx * m) / n
return (m, b)

if trend == None: 