Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. a <- rbinom(100, 1, .5)
  2. a <- sorted(a)
  3. holder <- data.frame(1:length(a), a)
  4.  
  5. ols <- lm(holder$a ~ holder$X1.length.a.)
  6.  
  7. resid <- holder$a - predict(ols)
  8.  
  9. plot(predict(ols),resid)
  10.  
  11.  
  12. normErr.Small <- lapply(1:100, function(x) {
  13. x + rnorm(n = 1, 1, sd = 1)
  14.  
  15. })
  16.  
  17. dat <- data.frame(x = 1:length(normErr.Small),y = unlist(normErr.small))
  18.  
  19. ols.small <- lm(y ~ x, data = dat)
  20. plot(ols.small, which = 1, main = "normal 1 1")
  21.  
  22. #larger variance
  23. normErr.Large <- lapply(1:100, function(x) {
  24. x + rnorm(n = 1, 1, sd = 10000)
  25.  
  26. })
  27.  
  28. dat <- data.frame(x = 1:length(normErr.Large),y = unlist(normErr.Large))
  29.  
  30. ols.Large <- lm(y ~ x, data = dat)
  31. plot(ols.Large, which = 1, main = "normal 1 10000")
  32.  
  33. normErr.Off <- lapply(1:100, function(x) {
  34. x + rnorm(n = 1, 10000, sd = 1)
  35.  
  36. })
  37.  
  38. dat <- data.frame(x = 1:length(normErr.Off),y = unlist(normErr.Off))
  39.  
  40. ols.Off <- lm(y ~ x, data = dat)
  41. plot(ols.Off, which = 1, main = "normal 10000 1")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement