Return slope in orthogonal regression problem

get_slope(x, y)

Arguments

x

vector with independent variable

y

vector with dependent variable

Value

the slope of the line that minimizes the total least squared error

Details

Whereas ordinary least squares finds the line that minimizes the sum of squared vertical distance, orthogonal regressions finds the line that minimizes the sum of vertical and horizontal differences.

See also

sum_squares(), get_slope_by_group() For a more general function (including one that returns the intercept), see pracma::odregress()

Examples

n <- 1000 z <- rnorm(n) x <- rnorm(n, z) y <- rnorm(n, 2 * z + 1) get_slope(x, y)
#> [1] 2.003767