Math calculators

Regression and correlation

Slope, intercept, R², standard errors, p-value, residuals, and Pearson and Spearman correlation.

Inputs

Results

Methodology

Conventions

  • Ordinary least squares fit of y on x. The p-value tests a zero slope with a two-sided t test on n − 2 degrees of freedom.
  • Spearman's ρ is Pearson's r on the ranks, with ties given their average rank.

References

  • Montgomery, Peck and Vining, Introduction to Linear Regression Analysis, 6th ed. (2021)

Formulas

Slope
\hat\beta = \frac{\sum (x_i - \bar x)(y_i - \bar y)}{\sum (x_i - \bar x)^2}
Intercept
\hat\alpha = \bar y - \hat\beta \bar x
R²
R^2 = 1 - \frac{\sum e_i^2}{\sum (y_i - \bar y)^2}
Slope standard error
SE(\hat\beta) = \sqrt{\frac{\sum e_i^2 / (n - 2)}{\sum (x_i - \bar x)^2}}