## Paul Johnson ## 2015-03-12 ## If you run this in R studio, "dev.new()" will fail. ## IN Rstudio, necessary to replace dev.new with: ## Macintosh: quartz() ## Windows: windows() set.seed(234324) x <- rnorm(1000, m =50, s = 20) e <- 10 * rnorm(1000, m = 0, s = 1) y1 <- 0.5 + 0.01 * x + e plot(y1 ~ x, ylim = c(-50, 425)) m1 <- lm (y1 ~ x) summary(m1) abline(m1, col="red") dev.new() y2 <- 0.5 + 0.05 * x + e plot(y2 ~ x) m2 <- lm (y2 ~ x) abline(m2, col = "red") summary(m2) y3 <- 0.5 + 0.15 * x + e plot(y3 ~ x) m3 <- lm (y3 ~ x) summary(m3) y4 <- 0.5 + 0.45 * x + e plot(y4 ~ x) m4 <- lm (y4 ~ x) abline(m4, col = "red") summary(m4) y5 <- 0.5 + 3.45 * x + e plot(y5 ~ x) m5 <- lm (y5 ~ x) abline(m5, col = "red") summary(m5) ## Plot y1 on same scale, get the idea? dev.new() plot(y1 ~ x, ylim = range(y5)) abline(m1, col = "red") ## Now wonder, what if error term's standard ## deviation is increased? What changes ## Recall ## e <- 10 * rnorm(1000, m = 0, s = 1) e1 <- e y1 <- 0.5 + 0.25 * x + e1 plot(y1 ~ x) m1 <- lm (y1 ~ x) summary(m1) abline(m1, col="red") ## Recall ## e <- 10 * rnorm(1000, m = 0, s = 1) ## Now sd of error is 50 = 5 * 10 e2 <- 5 * e ## Now true SD of error is 5 * 10 y2 <- 0.5 + 0.25 * x + e2 dev.new() plot(y2 ~ x) m2 <- lm (y2 ~ x) summary(m2) abline(m2, col="red") ## Recall ## e <- 10 * rnorm(1000, m = 0, s = 1) ## Now make true sd of error 150 e3 <- 15 * e ## Now true SD of error is 15 * 10 y3 <- 0.5 + 0.25 * x + e3 plot(y3 ~ x) m3 <- lm (y3 ~ x) summary(m3) abline(m3, col="red") ## Now make true sd of error 150 e4 <- 50 * e ## Now true SD of error is 50 * 10 y4 <- 0.5 + 0.25 * x + e4 plot(y4 ~ x) m4 <- lm (y4 ~ x) summary(m4) abline(m4, col="red") dev.new() plot(y1 ~ x, ylim = range(y4)) abline(m1, col = "red")