Linear regression is the workhorse of data analysis. Given a set of (x, y) pairs, it finds the single straight line that minimises the total squared distance from every point to the line — the ordinary least-squares (OLS) line. Whether you are studying hours versus exam scores, advertising spend versus sales, temperature versus crop yield, or any other two numeric variables, this calculator gives you the complete statistical picture in seconds, entirely in your browser.
How it works
The calculator solves the normal equations for simple linear regression:
β₁ = SS_xy / SS_xx where SS_xy = Σ(xᵢ − x̄)(yᵢ − ȳ) and SS_xx = Σ(xᵢ − x̄)²
β₀ = ȳ − β₁ · x̄
Once β₀ and β₁ are known, every fitted value is ŷᵢ = β₁xᵢ + β₀ and every residual is eᵢ = yᵢ − ŷᵢ. From these the calculator computes:
- Pearson r = SS_xy / √(SS_xx · SS_yy) — linear correlation, −1 to +1
- R² = r² — fraction of variance in y explained by x
- RSE = √(SSE / (n − 2)) — residual standard error, the typical prediction error in y-units
- SE(β₁) = RSE / √SS_xx — uncertainty around the slope
- SE(β₀) = RSE · √(Σxᵢ² / (n · SS_xx)) — uncertainty around the intercept
- t-statistics for both coefficients: t = estimate / SE
- Full ANOVA table with regression, error and total rows
The interactive scatter plot draws the fitted line over the data points and labels R² directly on the chart for immediate visual confirmation.
Worked example — study hours vs exam score
Using the built-in demo data (12 students, study hours 1–10, scores 52–97):
| Statistic | Value |
|---|---|
| Slope β₁ | 5.0559 |
| Intercept β₀ | 45.9779 |
| R | 0.9944 |
| R² | 0.9888 |
| RSE | 1.43 |
Interpretation: The regression line is ŷ = 5.06·x + 46.0. Each extra hour of study predicts roughly 5 more marks. R² = 0.989 means study hours explain 98.9% of the variance in exam scores for this sample — an almost perfectly linear relationship. The RSE of 1.43 marks tells you the model’s typical prediction error is less than 1.5 marks.
Prediction: A student who studies 7.5 hours is predicted to score ŷ = 5.06 × 7.5 + 46.0 = 83.9 marks.
Formula reference
Slope β₁ = Σ(xᵢ−x̄)(yᵢ−ȳ) / Σ(xᵢ−x̄)²
Intercept β₀ = ȳ − β₁·x̄
Fitted ŷᵢ = β₁·xᵢ + β₀
Residual eᵢ = yᵢ − ŷᵢ
SSE Σeᵢ²
RSE √(SSE/(n−2))
SE(β₁) RSE / √SS_xx
SE(β₀) RSE · √(Σxᵢ²/(n·SS_xx))
r SS_xy / √(SS_xx · SS_yy)
R² r²
All computations happen in your browser. No data is ever sent to a server.