Regressão Linear y = ax + b
Ajusta reta y = ax + b por mínimos quadrados a partir de pares X, Y.
a, b
—
Simple linear regression — coefficients (a, b)
Ordinary least squares (OLS) fits the line y = a·x + b by making the sum of squared residuals as small as it can be. The slope comes out as a = Σ((xᵢ−x̄)(yᵢ−ȳ)) / Σ(xᵢ−x̄)² and the intercept as b = ȳ − a·x̄. The coefficient of determination R² = SSR/SST tells you how much of the variance in Y the model accounts for. Run X=[1,2,3,4,5], Y=[2.1,3.9,6.2,7.8,10.1] through it and you get a ≈ 2.00, b ≈ 0.04 and R² ≈ 0.999. Every estimate carries a standard error, which is what lets you run t-tests against H₀: coefficient = 0. Legendre published the method in 1805 and Gauss in 1809.
Applications
Forecasting sales, experimental physics (Hooke's law F = k·x, Ohm's law V = R·I), econometrics like the Phillips curve and demand functions, classical machine learning with scikit-learn LinearRegression, calibration curves in pharmacology, and quality control on the engineering side.
FAQ
Gauss-Markov assumptions? Linearity, independent errors, homoscedasticity (constant variance) and normal residuals. Those are what OLS needs to be BLUE, the best linear unbiased estimator.
R² close to 1 is always good? Not necessarily. A high R² can also signal overfitting or a spurious correlation. Look at the residual plots, and when you're comparing models with different numbers of predictors, lean on adjusted R² instead.
What about non-linear data? Transform it first (log, √) or switch to polynomial or non-linear regression. For outliers, robust regression such as Huber or RANSAC handles them well.
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.