OLS - Ordinary Least Squares
Overview
The Ordinary Least Squares (OLS) estimator provides linear regression analysis with comprehensive statistical inference capabilities. It includes heteroskedasticity-robust standard errors and intelligent numerical algorithm selection for optimal performance across diverse problem specifications.
Mathematical Foundation
The Linear Model
where \(\mathbf{y}\) is the dependent variable vector, \(\mathbf{X}\) is the design matrix, \(\mathbf{\beta}\) is the parameter vector, and \(\mathbf{\epsilon}\) is the error term.
OLS Estimator
Statistical Properties
Finite Sample Properties (under Gauss-Markov assumptions): - Unbiased: \(E[\hat{\mathbf{\beta}}|\mathbf{X}] = \mathbf{\beta}\) - Efficient: Best Linear Unbiased Estimator (BLUE) - Covariance: \(\text{Var}(\hat{\mathbf{\beta}}|\mathbf{X}) = \sigma^2(\mathbf{X}'\mathbf{X})^{-1}\)
Robust Standard Errors: White (1980) heteroskedasticity-consistent estimator: \(\(\hat{\mathbf{V}}_{HC0} = (\mathbf{X}'\mathbf{X})^{-1}\mathbf{X}'\mathbf{\Omega}\mathbf{X}(\mathbf{X}'\mathbf{X})^{-1}\)\)
API Reference
Constructor
Parameters:
- fit_intercept (bool): Whether to calculate the intercept
- robust (bool): Whether to use heteroskedasticity-robust standard errors
Methods
fit()
Fit the OLS model using optimized algorithms.Parameters:
- X (np.ndarray): Training data matrix
- y (np.ndarray): Target values
predict()
Generate predictions using the fitted model.Statistical Methods
standard_errors()→ Standard errors of coefficientst_statistics()→ T-statistics for significance testsp_values()→ P-values for coefficient testsconfidence_intervals(alpha=0.05)→ Confidence intervalssummary()→ Comprehensive regression summarycovariance_matrix()→ Coefficient covariance matrix
Properties
Core Results:
- coefficients: Regression coefficients
- intercept: Regression intercept
- fit_intercept: Whether intercept is included
- robust: Whether robust standard errors are used
Statistical Measures:
- r_squared: Coefficient of determination
- r_squared_adj: Adjusted R-squared
- mse: Mean squared error
- residuals: Regression residuals
Model Information:
- n_samples: Number of observations
- n_features: Number of features
Implementation Details
Numerical Algorithms
- Cholesky Decomposition: Primary method for well-conditioned problems
- SVD: Fallback for ill-conditioned or rank-deficient matrices
- Automatic Selection: Based on condition number and problem structure
Performance Features
- Memory-efficient computation
- Vectorized operations using optimized BLAS
- Cache-optimized memory access patterns
Usage Guidelines
Use OLS when: - Linear relationship between variables - Exogenous regressors (no endogeneity) - Need for computational efficiency - Establishing baseline results
Consider alternatives when: - Heteroskedasticity → WLS - Error correlation → GLS - Endogeneity → IV or TSLS - Panel data → FE