Guest User

Untitled

a guest
Dec 12th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. library(MASS)
  2.  
  3. beta_1 <- data.frame(ls=rep(0,1000), bisq=rep(0,1000))
  4. for (i in 1:nrow(beta_1)) {
  5. x <- rnorm(100)
  6. y <- x + rt(100,3)
  7. beta_1$ls[i] <- lm(y~x)$coefficients["x"]
  8. beta_1$bisq[i] <- rlm(y~x, psi=psi.bisquare)$coefficients["x"]
  9. }
  10.  
  11. apply(beta_1, 2, sd)
  12.  
  13. > apply(beta_1, 2, sd)
  14. ls bisq
  15. 0.1809239 0.1296139
  16.  
  17. beta_1 <- data.frame(ls=rep(0,1000), bisq=rep(0,1000))
  18. for (i in 1:nrow(beta_1)) {
  19. x <- rnorm(100)
  20. y <- x + rnorm(100)
  21. z <- rbinom(100,1,0.05)
  22. y <- y + z*rnorm(100,0,5)
  23. beta_1$ls[i] <- lm(y~x)$coefficients["x"]
  24. beta_1$bisq[i] <- rlm(y~x, psi=psi.bisquare)$coefficients["x"]
  25. }
  26.  
  27. > apply(beta_1, 2, sd)
  28. ls bisq
  29. 0.1518029 0.1147156
Add Comment
Please, Sign In to add comment