stats.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:nmmn 作者: rsnemmen 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号