Skip to content

Instantly share code, notes, and snippets.

@gibsramen
Last active January 11, 2017 22:02
Show Gist options
  • Save gibsramen/e9e69231c70a3701fd8b8754a8f94252 to your computer and use it in GitHub Desktop.
Save gibsramen/e9e69231c70a3701fd8b8754a8f94252 to your computer and use it in GitHub Desktop.
x <- 1:10
y <- 1 + 2.5 * x
N <- length(x)
x_mean <- mean(x)
y_mean <- mean(y)
m <- sum((x - x_mean) * (y - y_mean)) / sum((x - x_mean)^2)
b <- y_mean - m * x_mean
# m = 2.5
# b = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment