Advertisement
VRonin

Plots

Jul 9th, 2012
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 3.37 KB | None | 0 0
  1. #Esercizio: Piombo e Traffico
  2. Piombo <- c(44, 58, 43, 60, 23, 53, 48, 74, 14, 38, 50, 55, 14, 67, 66, 18, 32, 20, 30)
  3. Traffico <- c(69, 109, 90, 104, 57, 111, 124, 127, 54, 102, 121, 118, 35, 138, 135, 70, 90, 50, 70)
  4. Modello <- lm(Piombo ~ Traffico)
  5. summary(Modello)
  6. Pred.OttoSette<-predict(Modello, data.frame(Traffico = 87), interval="confidence", level=0.95)
  7. Pred.UnoCinqueZero<-predict(Modello, data.frame(Traffico = 150), interval="confidence", level=0.95)
  8. #Assicurati che esista la cartella C:\Temp o metti una qualsiasi altra cartella
  9. png(filename="C:/Temp/Regressione.png")
  10. plot(x=Traffico, y=Piombo, type="p", pch=16, main="Valori Reali e Retta di regressione", xlab="Traffico", ylab="Piombo")
  11. lines(x=Traffico, y=Modello$fitted.values, type="l", col="red")
  12. dev.off()
  13. png(filename="C:/Temp/Previsioni.png")
  14. plot(x=Traffico, y=Modello$fitted.values, type="l", main="Valori Attesi e Intervalli di Confidenza", sub="Per Traffico=87 e 150", xlab="Traffico", ylab="Piombo", xlim=c(30,150) ,ylim=c(10,Pred.UnoCinqueZero[,3]))
  15. lines(c(87,150),c(Pred.OttoSette[,1],Pred.UnoCinqueZero[,1]),col="blue",type="p",pch=16)
  16. lines(c(87,87),c(Pred.OttoSette[,2],Pred.OttoSette[,3]),col="red",lty=2)
  17. lines(c(150,150),c(Pred.UnoCinqueZero[,2],Pred.UnoCinqueZero[,3]),col="red",lty=2)
  18. dev.off()
  19. #I grafici li trovi nella cartella C:\Temp
  20.  
  21. #Esercizio: Teyler’s Kernal & Red Charles Ross
  22. Teyler <- c(22, 24.5, 25.5, 27.5, 22.5, 27.5, 24, 26.5, 23.5, 25)
  23. Charles <- c(18.3, 18.4, 20.2, 22, 17.5, 18.1, 17.6, 16.8, 18.8, 18.9)
  24. summary(Teyler)
  25. summary(Charles)
  26.  
  27. Test.Zero<-t.test(Teyler, Charles)
  28. emp<-seq(-max(Teyler-Charles),max(Teyler-Charles),length=1000)
  29. png(filename="C:/Temp/Test Uguaglianza.png")
  30. plot(emp,dt(emp,Test.Zero$parameter),type="l",xlab="t",ylab="f(t)", main="Test per l'uguaglianza di Teyler e Charles")
  31. lines(x=rep(8.023339,2),y=c(-0.1,0.4),type="l",col="red", lty=2)
  32. lines(x=rep(qt(0.95,Test.Zero$parameter),2),y=c(-0.1,0.4),type="l",col="green", lty=2)
  33. legend(-max(Teyler-Charles),0.4,legend=c("Distribuzione t di Student","Statistica Test","95o Percentile"),col=c("black","red","green"),lty=c(1,2,2),cex=0.8)
  34. dev.off()
  35.  
  36. Test.Uno<-t.test(Teyler, Charles, mu=1)
  37. emp<-seq(-max(Teyler-Charles-1),max(Teyler-Charles-1),length=1000)
  38. png(filename="C:/Temp/Test Differenza 1.png")
  39. plot(emp,dt(emp,Test.Uno$parameter),type="l",xlab="t",ylab="f(t)", main="Test per la differenza di Teyler e Charles uguale a 1")
  40. lines(x=rep(Test.Uno$statistic,2),y=c(-0.1,0.4),type="l",col="red", lty=2)
  41. lines(x=rep(qt(0.95,Test.Uno$parameter),2),y=c(-0.1,0.4),type="l",col="green", lty=2)
  42. legend(-max(Teyler-Charles-1),0.4,legend=c("Distribuzione t di Student","Statistica Test","95o Percentile"),col=c("black","red","green"),lty=c(1,2,2),cex=0.8)
  43. dev.off()
  44.  
  45. Test.Teyler<-t.test(Teyler)
  46. emp<-seq(-max(Teyler),max(Teyler),length=1000)
  47. png(filename="C:/Temp/Media Teyler.png")
  48. plot(mean(Teyler)+emp,dt(emp,Test.Teyler$parameter),type="l",xlab="t",ylab="f(t)", main="Distribuzione della madia campionaria di Teyler")
  49. lines(x=rep(mean(Teyler),2),y=c(-0.1,0.4),type="l",col="red", lty=2)
  50. lines(x=rep(Test.Teyler$conf.int[1],2),y=c(-0.1,0.4),type="l",col="green", lty=2)
  51. lines(x=rep(Test.Teyler$conf.int[2],2),y=c(-0.1,0.4),type="l",col="green", lty=2)
  52. legend(-2.5,0.4,legend=c("Distribuzione t di Student","Stima della media","Intervallo di Confidenza al 95%"),col=c("black","red","green"),lty=c(1,2,2),cex=0.8)
  53. dev.off()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement