Linear Regression & Correlation Workbench

Fit ordinary least-squares (OLS) linear regression lines and compute Pearson r, Spearman rho, R², and standard errors with scatter plots.

Empirical Datasets:
Accepts comma, tab, semicolon, or space-separated pairs. Lines starting with # are treated as comments.

Model Parameters & Standard Errors

Valid Observations (n):9
Slope (m):10.165405
Y-Intercept (b):27.536709
Slope Std Error (SE_m):±0.306880
Intercept Std Error (SE_b):±1.384065
Residual Std Error (s_e):1.637782
Best-Fit OLS Equation
y = 10.1654x + 27.5367
Pearson Correlation (r)
0.99683
Coefficient of Determination (R²)
0.99366
Spearman Rank Correlation (ρ)
1.00000

Interactive Scatter Plot & OLS Trendline

Ordinary Least Squares (OLS) & Correlation Mechanics

Simple linear regression models the functional relationship between an independent explanatory variable X and a continuous dependent response variable Y using a first-order linear trendline equation:

ŷi = m × xi + b

The Ordinary Least Squares (OLS) criterion identifies parameter estimates (slope m, intercept b) that minimize the total sum of squared vertical residuals (errors):

minm, b ∑ ei2 = minm, b ∑ [ yi − (m × xi + b) ]2

Solving the first-order partial derivatives yields the closed-form analytical equations for slope and intercept:

m = [ N∑xy − (∑x)(∑y) ] / [ N∑x2 − (∑x)2 ]
b = ( ∑y − m∑x ) / N

Gauss-Markov BLUE Theorem: Under the classical assumptions of linearity, strict exogeneity (E[ei | X] = 0), homoscedasticity (Var(ei) = σ2), and uncorrelated errors (Cov(ei, ej) = 0), the OLS estimator is the Best Linear Unbiased Estimator (BLUE).

Anscombe's Quartet & The Perils of Blind Trendline Fitting

In 1973, statistician Francis Anscombe constructed four synthetic 11-point datasets demonstrating that identical summary statistics can describe radically different distributions:

Dataset Statistical Properties True Underlying Geometry OLS Validity
Dataset I m=0.50, b=3.00, R²=0.67 Standard linear relationship with homoscedastic noise Valid OLS Fit
Dataset II m=0.50, b=3.00, R²=0.67 Strictly non-linear parabolic curve (quadratic curve) Invalid (Model Misspecification)
Dataset III m=0.50, b=3.00, R²=0.67 Tightly linear slope offset by a single extreme outlier Requires Robust Regression
Dataset IV m=0.50, b=3.00, R²=0.67 Identical X coordinates with one high-leverage point Spurious Correlation

Key Takeaway: Never report Pearson r or R² in isolation without inspecting the visual scatter plot and residual variance distribution provided by OmniTools.

Diagnostic Metrics Comparison: Pearson r, R², & Spearman ρ

Evaluating bivariate data requires choosing the appropriate statistical metric for your dataset's distribution:

Metric Domain Target Association Outlier Sensitivity Recommended Scenario
Pearson r [-1.0, +1.0] Strictly linear direction and strength High (Quadratic penalty) Normally distributed continuous variables
R² (Coefficient of Det.) [0.0, 1.0] Proportion of variance explained by model High Evaluating goodness-of-fit for linear predictions
Spearman ρ [-1.0, +1.0] Monotonic trends (preserves rank order) Low (Robust rank transform) Skewed data, ordinal ranks, or non-linear power laws
Residual Std Error (se) [0.0, ∞) Average dispersion of observed points around trendline Moderate Constructing prediction and confidence intervals

Developer Cheatsheet: Python, R & Node.js Reference Code

Reproduce OmniTools linear regression results in your data science pipeline:

  • Python (SciPy & NumPy):
    from scipy import stats
    import numpy as np
    
    x = np.array([1, 2, 3, 4, 5])
    y = np.array([2.1, 3.8, 6.2, 8.1, 10.2])
    
    slope, intercept, r_val, p_val, std_err = stats.linregress(x, y)
    spearman_rho, _ = stats.spearmanr(x, y)
    print(f"y = {slope:.4f}x + {intercept:.4f} (R2={r_val**2:.4f})")
  • R Language:
    df <- data.frame(x = c(1, 2, 3, 4, 5), y = c(2.1, 3.8, 6.2, 8.1, 10.2))
    model <- lm(y ~ x, data = df)
    summary(model)  # Reports coefficients, R2, and p-values
    cor(df$x, df$y, method = "spearman")

Practical Real-World Use Cases

Ordinary Least Squares regression and correlation analysis are core analytical techniques across engineering, finance, and growth analytics:

  • Marketing Attribution & Ad Spend ROAS Modeling: Growth marketing teams model incremental revenue against paid ad spend per acquisition channel. The regression slope m represents marginal ROAS (Return on Ad Spend), while the intercept b estimates organic baseline conversions with zero ad budget.
  • Financial Beta & Capital Asset Pricing (CAPM): Quantitative analysts estimate an individual equity's systemic market risk (β) by regressing stock asset returns against a benchmark index (e.g., S&P 500 ETF). A slope β > 1 indicates magnified cyclical volatility, while R2 measures benchmark co-movement.
  • Scientific Sensor Calibration & Experimental Metrology: Hardware engineers calibrate analog sensors (thermistors, strain gauges, pressure transducers) by plotting physical standards against raw ADC millivolt readings. The regression equation forms the firmware conversion formula, and residual analysis reveals non-linear transducer saturation.
  • Machine Learning Baseline Benchmark: Data scientists run OLS regression before training deep neural networks or gradient-boosted trees (XGBoost), providing a transparent, interpretable benchmark to verify whether complex non-linear models justify added compute overhead.

Absolute Privacy & Zero Server Upload

Scientific research datasets, financial performance figures, and proprietary business metrics contain confidential information. OmniTools runs 100% locally in your browser using pure client-side numerical arithmetic:

  • Zero Network Transmissions: Your data pairs, regression coefficients, and calculated residuals never leave your local browser or reach a remote server.
  • Zero Telemetry or Data Mining: No third-party analytics intercept or log your research data.
  • Instant Offline Performance: Perform statistical regressions and generate high-DPI Canvas scatter plots entirely offline without an internet connection.

Frequently Asked Questions

How do you calculate the Ordinary Least Squares (OLS) linear regression line y = mx + b?

Paste your paired (x, y) data points to compute the exact slope (m), y-intercept (b), Pearson correlation coefficient (r), coefficient of determination (R²), standard error, and residual table with an interactive scatter plot.

What is the difference between Pearson correlation (r) and R-squared (R²)?

Pearson r (ranging from −1 to +1) measures the strength and direction of a linear relationship, whereas R² (ranging from 0 to 1) measures the proportion of variance in the dependent variable y explained by x.