Regressions

linregress

isopy.tb.linregress(x, y)[source]

Calculate a linear least-squares regression for two sets of measurements.

Uses scipy.stats.linregress(x, y) for the regression. See `here<https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.linregress.html>`_ for the scipy documentation.

Parameters
  • x (numpy_array_like) – Data points through which the regression should be calculated.

  • y (numpy_array_like) – Data points through which the regression should be calculated.

Returns

result – The returned object contains the following attributes:

  • slope - Slope of the regression line.

  • intercept - Intercept of the regression line.

  • slope_se - Standard error of the slope.

  • intercept_se - Standard error of the intercept.

  • df - The degrees of freedom of the regression (N - 2).

The returned object also contains the following methods:

  • y(x) - Returns the value of y at x

  • label(sigfig) - Returns a string in the format “y=mx + c” with sigfig significant figures.

Return type

LinregressResult

yorkregress

isopy.tb.yorkregress(x, y, xerr, yerr, r=0, err_ci=None, err_zscore=None, result_ci=None, result_zscore=None, tol=1e-10)[source]

Calculate the slope and intercept taking into account the uncertainty on x and y.

Uncertainties on the slope and intercept are given as standard errors. Based on the formulas from York et al. (2004) American Journal of Physics 72, 367.

If neither err_ci or err_zscore are given it assumes the uncertainties represent 1 SD/SE. If neither result_ci or result_zscore are giuen the err_ci/err_zscore is also used for the uncertainty on the slope and intercept.

The functions yorkregress2 and yorkregress3 are also avaliable with preset values for err_zscore of 2 and 3 respectively. Similarly, yorkregress95 and yorkregress99 exists with preset values err_ci 0.95 and 0.99.

Parameters
  • x (numpy_array_like) – Data points through which the regression should be calculated.

  • y (numpy_array_like) – Data points through which the regression should be calculated.

  • xerr (numpy_array_like) – Uncertainties for x and y values. Can be an array with the same size as x and y or a scalar value which will be used for every datapoint.

  • yerr (numpy_array_like) – Uncertainties for x and y values. Can be an array with the same size as x and y or a scalar value which will be used for every datapoint.

  • r (float, optional) – Correlation coefficient between errors in x and y. Default value is 0.

  • err_ci (float, optional) – The confidence interval of xerr and yerr.

  • err_zscore (float, optional) – The zscore of xerr and yerr.

  • result_ci (float, optional) – The desired confidence interval of the uncertainty on the slope and intercept.

  • result_zscore (float, optional) – The desired zscore of the uncertainty on the slope and intercept.

  • tol (float, optional) – Tolerance for fit. Default value is 1e-10.

Returns

result – The returned object contains the following attributes:

  • slope - The slope of the regression

  • intercept - The y-axis intercept of the regression

  • slope_se - The standard error of the slope

  • intercept_se - The standard error of the y-axis intercept

  • msdw - The mean square weighted deviate of the regression.

  • df - The degrees of freedom of the regression (N - 2).

  • pvalue - The two-tailed probability of the chi-squared value with df degrees of freedom.

The returned object also contains the following methods:

  • y(x) - Returns the value of y at x

  • yerr(x) - Returns the standard error on y at x.

  • label(sigfig) - Returns a string in the format “y=mx + c, msdw” with sigfig significant figures.

Return type

YorkregressResult