Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. YEAR <- 1:29
  2.  
  3. ROLL <- c( 5501, 5945, 6629 ,7556 ,8716 ,9369 ,9920,10167,11084,12504,13746, 13656, 13850,14145,14888,14991,14836,14478,14539,14395,14599,14969,15107,14831, 15081,15127,15856,15938,16081)
  4.  
  5.  
  6. UNEM <- c(8.1,7.0, 7.3, 7.5, 7.0, 6.4, 6.5,6.4,6.3,7.7,8.2,7.5,7.4,8.2, 10.1,9.2,7.7,5.7,6.5,7.5,7.3,9.2,10.1,7.5,8.8,9.1,8.8,7.8,7.0)
  7.  
  8. datavar <- data.frame(YEAR=YEAR,ROLL=ROLL,UNEM=UNEM)
  9.  
  10. res.lm <- lm(ROLL ~ UNEM, datavar)
  11. library(lattice)
  12. x11()
  13. xyplot(ROLL~UNEM, data=datavar)
  14.  
  15. summary(res.lm)
  16. names(res.lm)
  17. x11()
  18. xyplot(ROLL~YEAR, data=datavar)
  19.  
  20. cat("The TRUE value of Intercept and Slope are : ", res.lm$coefficients , "n")
  21.  
  22.  
  23. n <- nrow(datavar)
  24.  
  25. intercept <- NULL
  26. slope <- NULL
  27.  
  28. sigma <- summary(res.lm)$sigma
  29. set.seed(36)
  30. for(i in 1:1000){
  31. n.error <- rnorm(n,mean=0,sd=sigma)
  32. nROLL <- res.lm$coefficients[1] + res.lm$coefficients[2]*datavar$UNEM + n.error
  33. ndatavar <- data.frame(datavar,nROLL=nROLL)
  34. nres.lm <- lm(nROLL ~ UNEM, ndatavar)
  35. intercept[i] <- nres.lm$coefficients[1]
  36. slope[i] <- nres.lm$coefficients[2]
  37. }
  38.  
  39. par(mfrow=c(1,2))
  40. hist(intercept,freq=FALSE)
  41. abline(v=res.lm$coefficients[1],col=2)
  42.  
  43. hist(intercept,freq=FALSE)
  44. abline(v=res.lm$coefficients[2],col=2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement