def scatterfit(x,y,a=None,b=None):
"""
Compute the mean deviation of the data about the linear model given if A,B
(*y=ax+b*) provided as arguments. Otherwise, compute the mean deviation about
the best-fit line.
:param x,y: assumed to be Numpy arrays.
:param a,b: scalars.
:rtype: float sd with the mean deviation.
"""
if a==None:
# Performs linear regression
a, b, r, p, err = scipy.stats.linregress(x,y)
# Std. deviation of an individual measurement (Bevington, eq. 6.15)
N=numpy.size(x)
sd=1./(N-2.)* numpy.sum((y-a*x-b)**2)
sd=numpy.sqrt(sd)
return sd
评论列表
文章目录