Home / Shared Math Details / Shared Estimators and Tests / Weighted Least Squares (QR)
Weighted Least Squares (QR)¶
This page defines the weighted least-squares fit, solved by QR decomposition, that Quantum XL uses to fit regression models and trend lines.
Notation¶
| Term | Description |
|---|---|
| \(\mathbf{x}_i\) | the model terms (row of the design matrix) at observation \(i\) |
| \(X\) | design matrix whose rows are the \(\mathbf{x}_i\) |
| \(y_i\) | response value at observation \(i\) |
| \(w_i\) | weight (frequency) of observation \(i\) |
| \(W\) | diagonal matrix of the weights \(w_i\) |
| \(\boldsymbol\beta\) | fitted coefficients |
| \(N\) | total weight \(\sum_i w_i\) |
| \(p\) | number of parameters (columns of \(X\)) |
Model¶
Quantum XL fits \(y \approx X\boldsymbol\beta\) by minimizing the weighted sum of squared residuals:
The design-matrix row depends on the model: \([\,1,\ x\,]\) for a line, \([\,1,\ x,\ x^2,\ \dots,\ x^d\,]\) for a degree-\(d\) polynomial, and \([\,1,\ \ln x\,]\) for a logarithmic fit.
QR solution¶
Quantum XL scales each row by \(\sqrt{w_i}\), forming the weighted system \(X^{*} = \sqrt{W}\,X\) and \(y^{*} = \sqrt{W}\,y\) (so that \(X^{*\top}X^{*} = X^{\top}WX\)), then solves it by Householder QR decomposition:
The solution is obtained by back-substitution on the first \(p\) rows. A near-singular system (any \(|R_{ii}| < 10^{-14}\)) is rejected rather than solved.
Shared fit statistics¶
The same weighted fit reports:
where \(\hat{y}_i\) is the fitted value, \(\bar{y}\) the weighted mean of the response, and \(N = \sum_i w_i\).
Used by¶
- Scatter Plot: the regression fit. The Scatter Plot page also documents the extras built on this solve (coefficient t-tests, the overall F-test, and VIF).
- Time Series: the trend fit, which uses weights of 1 for valid points and 0 to skip missing points.
See Also¶
References¶
- Golub, G. H., and Van Loan, C. F. (2013). Matrix Computations, 4th ed. Johns Hopkins University Press.
- Draper, N. R., and Smith, H. (1998). Applied Regression Analysis, 3rd ed. Wiley.