Guest User

Untitled

a guest
Jun 14th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. unm <- read.csv("enrollment.csv")
  2. plot(unm$unem,unm$enroll,xlab="Unemployment (%)",ylab="Enrollment")
  3. #
  4. # We could use our commands, but there is built in tools
  5. #
  6. res <- lm(enroll~unem,data=unm)
  7. names(res)
  8. res$coef
  9. res$fitted
  10. res$resid
  11. summary(res)
  12. #
  13. # We will discuss some of this output more in detail on Monday
  14. #
  15. plot(unm$unem,unm$enroll,xlab="Unemployment (%)",ylab="Enrollment")
  16. abline(res)
  17. confint(res)
  18. confint(res,level=.90)
  19. #
  20. # Predicted values based on model
  21. #
  22. xh <- data.frame(unem=7)
  23. predict(res,newdata=xh)
  24. xh <- data.frame(unem=c(6,7,8,9,10))
  25. predict(res,newdata=xh)
  26. predict(res,newdata=xh,se.fit=T)
  27. predict(res,newdata=xh,interval="confidence",level=.95)
  28. predict(res,newdata=xh,interval="prediction",level=.95)
  29. #
  30. # Can we graph this in a useful fashion?
  31. #
  32. attach(unm) # Break apart the file so we have easy access to data
  33. plot(unem,enroll,xlab="Unemployment (%)",ylab="Enrollment",pch=20)
  34. abline(res,lwd=2)
  35. newData <- data.frame(unem=seq(min(unem),max(unem),by=(max(unem)-min(unem))/45))
  36. conf.lim <- predict(res,newData,interval="confidence")
  37. pred.lim <- predict(res,newData,interval="prediction")
  38. matlines(newData$unem,conf.lim[,-1],col="red",lty=2)
  39. matlines(newData$unem,pred.lim[,-1],col="green",lty=3)
  40. legend(8.5,7000,legend=c("Fitted Line","Confidence Bands","Prediction Bands"),
  41. lty=c(1,2,3),col=c("black","red","green"))
Add Comment
Please, Sign In to add comment