Skip to content

Instantly share code, notes, and snippets.

@dreidpath
Created October 20, 2015 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dreidpath/6ca24e5006fa165f494a to your computer and use it in GitHub Desktop.
Save dreidpath/6ca24e5006fa165f494a to your computer and use it in GitHub Desktop.
require("devtools")
# Import a funrction that will take an R lm model expressed in terms of y ~ x. Provided values for y, return "estimated" x.
source_gist("https://gist.github.com/dreidpath/6ee2bb95c6010cff3874")
x <- 0:5 # Comment out this line on the second runs, and uncomment line 6
# x <- c(1, 0, 2:5) # Run this one second, and comment out line 5
cat("Mean of x:", mean(x))
cat("Variance of x:", var(x))
y <- 5:0
cat("Mean of y:", mean(y))
cat("Variance of y:", var(y))
plot(x, y)
lm_yx <- lm(y ~ x)
abline(lm_yx)
lm_xy <- lm(x ~ y)
x_vals <- returnXinY(lm_xy, 5:0)
lines(5:0, x_vals, col='red')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment