c:ms:2023:schedule:w10.lecture.note
This is an old revision of the document!
R code
set.seed(101) x <- rnorm(400, 100, 10) x y <- 1.4*x + 2 + rnorm(400, 0, 4) y df <- data.frame(x,y) # density graph ggplot(data=df, aes(y)) + geom_histogram() + geom_vline(aes(xintercept=mean(y)), color="red", linetype="dashed", size=1) + coord_flip() ggplot(data=df, aes(y)) + geom_density(color="blue", size=1.5) + geom_vline(aes(xintercept=mean(y)), color="red", linetype="dashed", size=1) + coord_flip() ggplot(data=df, aes(x,y)) + geom_point(color="blue", siz=1.5, pch=1.5) + stat_smooth(method = "lm", formula = y ~ x, geom = "smooth", color="red", size=1) set.seed(401) sn <- 25 x <- rnorm(sn, 100, 10) x y <- 1.4 * x + 2 + rnorm(sn, 0, 10) y df <- data.frame(x, y) # density graph ggplot(data=df, aes(y)) + geom_histogram() + geom_vline(aes(xintercept=mean(y)), color="red", linetype="dashed", size=1) + coord_flip() ggplot(data=df, aes(y)) + geom_density(color="blue", size=1.5) + geom_vline(aes(xintercept=mean(y)), color="red", linetype="dashed", size=1) + coord_flip() lm.mod <- lm(y~x, data=df) summary(lm.mod) str(lm.mod) inc.y <- lm.mod$coefficients[1] slope.x <- lm.mod$coefficients[2] inc.y slope.x ggplot(data=df, aes(x,y)) + geom_point(color="blue", size=1.5, pch=1.5) + geom_hline(aes(yintercept=mean(y))) + geom_abline(intercept=inc.y, slope=slope.x) ggplot(data=df, aes(x,y)) + geom_point(color="blue", size=2.5, pch=2) + geom_hline(aes(yintercept=mean(y)), size=1.5, color="red") + geom_abline(intercept=inc.y, slope=slope.x, size=1.5, color="darkgreen")
c/ms/2023/schedule/w10.lecture.note.1683476010.txt.gz · Last modified: 2023/05/08 01:13 by hkimscil