Logo

A physics toolbox for laser spectroscopy.

Static Badge Static Badge Static Badge

Static Badge Static Badge

© 2025 Patrick Müller. All rights reserved.

qspec.analyze.linear_fit  (  x y sigma_x = None sigma_y = None corr = None report = False ** kwargs  )[source]

Maximum likelihood fit for a straight line through points $\vec{\mu}_i\in\mathbb{R}^2$ with covariances $\mathbf{\Sigma}_i\in\mathbb{R}^{2\times 2}$, assuming $2$-dimensional multivariate normal distributions $\mathcal{N}(\vec{\mu}_i, \mathbf{\Sigma}_i)$. The data points and covariances are given by $$\vec{\mu} = \begin{pmatrix}x\\y\end{pmatrix},\quad \mathbf{\Sigma} = \begin{pmatrix} \sigma_x^2 & \rho_{xy}\sigma_x\sigma_y \\ \rho_{xy}\sigma_x\sigma_y & \sigma_y^2 \end{pmatrix}.$$ This is a wrapper for the more general linear_nd_fit function. The algorithm is described in qspec's publication.

Parameters:
xndarray | Iterable

The $x$ data.

yndarray | Iterable

The $y$ data.

sigma_xndarray | Iterable

The standard deviation $\sigma_x$ of the x data.

sigma_yndarray | Iterable

The standard deviation $\sigma_y$ of the y data.

corrndarray | Iterable

The correlation coefficients $\rho_{xy}$ between the x and y data.

reportbool

Whether to print the result of the fit.

kwargsNone

Additional keyword arguments.

Returns:
(popt, pcov)(ndarray, ndarray)

The best y-intercept and slope and their covariance matrix.

API navigation