- 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_fitfunction. The algorithm is described in qspec's publication.- Parameters:
-
- xarray_like
The $x$ data.
- yarray_like
The $y$ data.
- sigma_xarray_like | None
The standard deviation $\sigma_x$ of the
xdata. IfNone, it is 1.- sigma_yarray_like | None
The standard deviation $\sigma_y$ of the
ydata. IfNone, it is 1.- corrarray_like | None
The correlation coefficients $\rho_{xy}$ between the
xandydata. IfNone, it is 0.- reportbool
Whether to print the result of the fit.
- kwargsAny
Additional keyword arguments are accepted for compatibility with the other linear regression algorithms and ignored.
- Returns:
- Raises:
-
- numpy.linalg.LinAlgError
If a covariance matrix cannot be inverted.