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
Linear Regression (Least Squares)
Fit y = a·x + b by least squares; reports slope, intercept, R².
Linear Regression Slope and Intercept (Least Squares)
Paste two comma-separated lists of paired X and Y values and get the ordinary least squares coefficients a and b of the line y = ax + b.
Lead Screw Lead
Compute the lead of a ball screw or power screw, Lead = pitch · number of starts, the linear distance the nut travels per full turn of the screw. On a single-start screw the lead equals the pitch; with multiple starts the lead increases proportionally, allowing more linear speed at the same rotation. The basis of rotation-to-displacement conversion in CNC and linear actuators. Enter the pitch and the number of starts.
Timber Design Strength (kmod, NBR 7190)
Computes the timber design strength per the Brazilian NBR 7190, f_d = k_mod1 · k_mod2 · k_mod3 · f_k / γ_w, where the three modification factors correct the characteristic strength for load duration, service moisture class and timber grade, and γ_w is the material partial safety factor. Timber is the only common structural material whose strength falls with the DURATION of the applied load, and that is what k_mod1 encodes: it is 1.10 for instantaneous action and only 0.60 for permanent load, so the same member is worth nearly twice as much under impact as under self weight. In the most common design combination — long-duration action (0.70), moisture class 1 or 2 (1.00), first-grade sawn timber (1.00) and compression parallel to the grain with γ_wc = 1.4 — the factors cancel such that the design strength comes out exactly half the characteristic value, a shortcut worth memorising to sanity-check any result. Enter the three modification factors, the characteristic strength and the partial safety factor.
Logistic Odds Ratio
Computes odds ratio from logistic regression beta coefficient.
Linear Explosive Charge
Calculate the linear loading density of a blast hole, q = (π/4) × d² × ρ, from the hole diameter d (mm) and the explosive density ρ (g/cm³). The result, in kg of explosive per meter of hole, is how much explosive fits in each meter of charged column — a central parameter of rock blast design. Multiplied by the hole charge height, it gives the charge per hole; combined with the blasted rock volume, it gives the powder factor. Larger diameters and denser explosives raise the linear charge. Enter the hole diameter and the explosive density.
The results provided by this tool are for general informational and educational purposes only and do not constitute professional, financial, medical, legal, tax or accounting advice. Always confirm important decisions with a qualified professional and official sources.