Compute the best-fit line using Ordinary Least Squares (OLS). Instantly get slope, intercept, correlation coefficient (r), R², and residuals. Visualize data points and regression line on an interactive canvas.
Click or drag file here
Supports CSV, TSV, JSON (array of objects with x,y or [x,y] pairs)CSV/TSV:
x,y
1,2
2,3.5
3,4.8
JSON:
[{"x":1,"y":2},{"x":2,"y":3.5}] OR [[1,2],[2,3.5]]
Imagine you're a marketing analyst trying to predict sales based on advertising spend. Use the simulation below to see how changes in ad budget affect predicted sales.
Current Regression Model: ŷ = ? + ?·x
Predicted Sales: — (in $1000)
* This simulation uses the current data points from your analysis above. Click "Compute Regression" first to load a model.
Linear regression is a fundamental statistical method that models the relationship between a dependent variable (Y) and one independent variable (X) using a linear equation ŷ = b₀ + b₁x. The coefficients are estimated by minimizing the sum of squared vertical distances (residuals) between observed data and the line — the Ordinary Least Squares (OLS) criterion. This method was developed by Carl Friedrich Gauss and Adrien-Marie Legendre in the early 19th century and remains the backbone of predictive analytics, econometrics, and machine learning.
Formulas:
Slope: b₁ = Σ[(xᵢ - x̄)(yᵢ - ȳ)] / Σ(xᵢ - x̄)²
Intercept: b₀ = ȳ - b₁·x̄
Pearson correlation r = Cov(X,Y) / (σₓ·σᵧ) R² = r²
The relationship between X and Y is linear. Check by examining if residuals are randomly scattered around zero.
Observations are independent of each other. Particularly important in time series data.
Constant variance of residuals across all levels of X. Look for funnel shapes in residual plots.
Residuals should be approximately normally distributed for valid confidence intervals and p-values.
The correlation coefficient r ranges from -1 to +1, indicating strength and direction of linear association. R² (coefficient of determination) represents the proportion of variance in Y explained by X. For instance, R² = 0.85 means 85% of the variability is captured by the model. Our calculator also helps detect outliers — points that heavily influence slope — by visualizing residuals.
Classical linear regression assumes linearity, independence of errors, homoscedasticity (constant variance), and normality of residuals for valid inference. Our tool is designed for exploratory analysis and educational demonstration; for rigorous inferential statistics, additional diagnostics (like p-values, confidence intervals) are required. However, the numerical accuracy meets academic standards with double‑precision arithmetic.
The algorithm implemented uses the closed-form solution derived from calculus: partial derivatives of the sum of squared errors lead to normal equations. The slope formula reduces to the ratio of the covariance of X and Y to the variance of X. For computational stability, we use the two-pass method (mean centering) to avoid catastrophic cancellation. All calculations are performed locally on your device — no data is transmitted, ensuring absolute privacy.