Created
October 20, 2015 03:38
-
-
Save dreidpath/6ca24e5006fa165f494a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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