Created
April 1, 2015 19:16
-
-
Save rsnemmen/0eb32832c657c19e4d39 to your computer and use it in GitHub Desktop.
Computes the mean deviation of the data about the linear model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
x,y assumed to be Numpy arrays. a,b scalars. | |
Returns the float sd with the mean deviation. | |
Author: Rodrigo Nemmen | |
""" | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there some indentation missing here perhaps?