Univariate OLS regression of y on x: the slope, intercept, R-squared,
and the two-sided t-test of the slope. The slope, R-squared and p-value
reproduce base R stats::lm / summary.lm and scipy.stats.linregress
bit-for-bit (to machine precision against lm's QR path).
Value
A list with slope, intercept, r_squared, statistic (the
slope t-statistic), p_value (two-sided), df (n - 2) and n.
Examples
linearRegression(1:20, 2 * (1:20) + rnorm(20))
#> $slope
#> [1] 1.97987
#>
#> $intercept
#> [1] 0.2700651
#>
#> $r_squared
#> [1] 0.9854246
#>
#> $statistic
#> [1] 34.88495
#>
#> $p_value
#> [1] 5.542676e-18
#>
#> $df
#> [1] 18
#>
#> $n
#> [1] 20
#>