Linear Regression OLS Calculator
Computes simple linear regression coefficients by ordinary least squares method from a list of x y data pairs.
—
OLS coefficients: estimating slope and intercept
Ordinary Least Squares (OLS) finds the slope and intercept of y = a·x + b that drive the sum of squared residuals to its minimum. Because there's a closed-form answer, you never have to iterate: a = Σ((xᵢ − x̄)(yᵢ − ȳ)) / Σ(xᵢ − x̄)² and b = ȳ − a·x̄. As long as the four classical assumptions hold — linearity, independent errors, constant variance (homoscedasticity), normal residuals — the Gauss-Markov theorem guarantees that OLS is the Best Linear Unbiased Estimator, or BLUE. Run it on the pairs (1,2), (2,4), (3,5), (4,4), (5,7) and you land on x̄ = 3 and ȳ = 4.4; the numerator comes to 11, the denominator to 10, so a = 1.1 and b = 4.4 − 1.1·3 = 1.1.
Applications
You'll find it as the baseline model in machine learning (sklearn.linear_model.LinearRegression, statsmodels OLS). Experimental physics leans on it to estimate Hooke's law F = k·x from spring measurements. Econometrics uses it for demand-supply elasticity or the Phillips curve, lab work uses it to calibrate analytical instruments, and it's the obvious choice whenever you forecast sales or costs from a single predictor.
FAQ
Why squared residuals instead of absolute values? Squaring gives you a smooth, convex loss that has a closed-form solution, and it punishes outliers harder, which is what you want when big errors are the ones that hurt.
What if Gauss-Markov assumptions fail? If the variance isn't constant, reach for weighted least squares or robust standard errors. If the residuals are correlated, you'll want GLS or a time-series model such as ARIMA.
How do I interpret the coefficients? a tells you how much y is expected to change when x goes up by one unit. b is the predicted y at x = 0, which often sits outside the range of your data, so treat any extrapolation there with caution.
Does OLS handle multiple predictors? Yes. The matrix form β̂ = (XᵀX)⁻¹Xᵀy extends the simple case straight into multiple linear regression.
Related Tools
Rent Adjustment Calculator
Compute annual rent adjustment by IGP-M or IPCA accumulated in the last 12 months (manually configurable).
Pregnancy Calculator
Compute estimated due date (EDD), gestational age and trimester from the last menstrual period (LMP).
Fertile Period Calculator
Compute fertile window and ovulation day from the first day of the last cycle and the average cycle length.