Advertisement
muridnyaindra

BAB IV

Nov 5th, 2019
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 3.44 KB | None | 0 0
  1. #2ST4TMATE
  2.  
  3. #One-way Analysis of variance
  4. data("chickwts")
  5. chick=chickwts
  6. by (data=chick$weight,INDICES = chick$feed, FUN = shapiro.test)
  7.  
  8. ##tes homogenitas variance
  9. bartlett.test(weight~feed, data=chick)
  10.  
  11.  
  12. ##################################################################################
  13.  
  14.  
  15. anova1=aov(weight~feed, data=chick)
  16. anova1
  17.  
  18. summary(anova1)
  19.  
  20.  
  21. ##################################################################################
  22.  
  23.  
  24. plot(weight~feed, data=chick)
  25.  
  26.  
  27. ##################################################################################
  28.  
  29.  
  30. pairwise.t.test(chick$weight,chick$feed,p.adj="bonferroni",paired=F)
  31.  
  32.  
  33. ##################################################################################
  34.  
  35.  
  36. TukeyHSD(anova1)
  37.  
  38.  
  39. ##################################################################################
  40.  
  41.  
  42. data("InsectSprays")
  43. Insect=InsectSprays
  44. #explore data
  45. dim(Insect)
  46.  
  47. head(Insect)
  48.  
  49. attach(Insect)
  50. summary(Insect)
  51.  
  52.  
  53. ##################################################################################
  54.  
  55.  
  56. require(stats); require(graphics)
  57. boxplot(count~spray, data=Insect, xlab="Type of spray", ylab="Insect count", main="Insect sprays data", varwidth=TRUE, col="lightgrey")
  58.  
  59.  
  60. ##################################################################################
  61.  
  62.  
  63. #One way analysis variance
  64. by(data=count, INDICES = spray, FUN=shapiro.test)
  65.  
  66. bartlett.test(count~spray)
  67.  
  68.  
  69. ##################################################################################
  70.  
  71.  
  72. aov.Insect=aov(count~spray,data=Insect)
  73. summary(aov.Insect)
  74.  
  75.  
  76. ##################################################################################
  77.  
  78.  
  79. TukeyHSD(aov.Insect)
  80.  
  81.  
  82. ##################################################################################
  83.  
  84. #Two-way anova
  85. hsb=data.frame(read.csv("PASTE DISINI FILE PATHNYA SAYANGG")) #mungkin datanya dikirim nanti hmm
  86. #uji homogen varian
  87. bartlett.test(science~c(female+schtyp), data=hsb)
  88.  
  89.  
  90. ##################################################################################
  91.  
  92.  
  93. anova2=aov(science~schtyp+female, data=hsb)
  94. summary(anova2)
  95.  
  96. pairwise.t.test(hsb$science,c(hsb$schtyp+hsb$female),p.adj="bonferroni", paired=F)
  97.  
  98.  
  99. ##################################################################################
  100.  
  101. #explore contoh 4.4
  102. data("ToothGrowth")
  103. Tooth=ToothGrowth
  104. str(Tooth)
  105.  
  106.  
  107. ##################################################################################
  108.  
  109.  
  110. Tooth$dose=as.factor(Tooth$dose)
  111. str(Tooth)
  112.  
  113.  
  114. ##################################################################################
  115.  
  116.  
  117. bartlett.test(len~supp, data = Tooth)
  118.  
  119. bartlett.test(len~dose, data=Tooth)
  120.  
  121.  
  122. ##################################################################################
  123.  
  124. #Anova two ways
  125. aov.vitc=aov(len~supp+dose, data=Tooth)
  126. summary(aov.vitc)
  127.  
  128.  
  129. ##################################################################################
  130.  
  131.  
  132. TukeyHSD(aov.vitc)
  133.  
  134.  
  135. ##################################################################################
  136.  
  137.  
  138. boxplot(len~supp+dose, data=Tooth, xlab="Dosin dan Metode Pemberian", ylab="Pertumbuhan gigi", main="Boxplot pemberian Vit C pada marmut")
  139.  
  140.  
  141. ##################################################################################
  142.  
  143.  
  144. coplot(len~dose|supp, data=Tooth, panel = panel.smooth, xlab="Toothgrowth data : length vs dose, given type of supplement")
  145.  
  146.  
  147. ##################################################################################
  148. #2ST4TMATE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement