linfit - import numpy as np import scipy.special as ss def...

This preview shows pages 1–2. Sign up to view the full content.

import numpy as np import scipy.special as ss def linfit(y, x=None, y_unc=None): ''' Fits a line to 2D data, optionally with errors in y. The method is robust to roundoff error. Parameters ---------- y: ndarray Ordinates, any shape. x: ndarray Abcissas, same shape. Defaults to np.indices(y.length)) y_unc: ndarray Uncertainties in y. If scalar or 1-element array, applied uniformly to all y values. [NOT IMPLEMENTED YET!] Must be positive. Returns ------- a: scalar 0 Fitted intercept b: scalar 1 Fitted slope a_unc: scalar 2 Uncertainty of fitted intercept b_unc: scalar 3 Uncertainty of fitted slope chisq: scalar 4 Chi-squared prob: scalar 5 Probability of finding worse Chi-squared for this model with these uncertainties. covar: ndarray 6 Covariance matrix: [[a_unc**2, covar_ab], [covar_ab, b_unc**2]] yfit: ndarray 7 Model array calculated for our abcissas Notes ----- If prob > 0.1, you can believe the fit. If prob > 0.001 and the errors are not Gaussian, you could believe the fit. Otherwise do not believe it.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern