Created
June 7, 2017 18:38
-
-
Save Ax3man/158576eee48904b0c3b4c06fc86acc3e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
library(tidyverse) | |
n <- 200 | |
step <- 0.02 | |
sm_step <- 0.02 | |
v <- 10 | |
tmp <- data_frame(x = 1:200, | |
a = x * 0 + rnorm(n, 0, v), | |
b = x * (0 - step - 1 * sm_step) + rnorm(n, 0, v) + (step + 1 * sm_step) * 100, | |
c = x * (0 - step - 2 * sm_step) + rnorm(n, 0, v) + (step + 2 * sm_step) * 100, | |
d = x * (0 - step - 3 * sm_step) + rnorm(n, 0, v) + (step + 3 * sm_step) * 100, | |
e = x * (0 - step - 4 * sm_step) + rnorm(n, 0, v) + (step + 4 * sm_step) * 100) | |
tmp2 <- gather(tmp, var, val, -x) | |
ggplot(tmp2, aes(x, val, col = var)) + geom_point() | |
fm <- lm(val ~ x * var, tmp2) | |
summary(fm) | |
tmp3 <- cbind(tmp2, predict(fm, interval = 'confidence')) | |
ggplot(tmp3, aes(x, fit, ymin = lwr, ymax = upr, col = var, fill = var)) + | |
geom_line() + | |
geom_ribbon(alpha = 0.3, col = NA) + | |
theme_bw() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment