User Tools

Site Tools


factorial_anova

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
factorial_anova [2024/09/23 23:21] – [예 1] hkimscilfactorial_anova [2026/04/23 03:29] (current) hkimscil
Line 290: Line 290:
  
 <code> <code>
-de <- read.csv("http://commres.net/wiki/_media/detergent.csv", sep = ",", header=T)+de <- read.csv("http://commres.net/_media/detergent.csv", sep = ",", header=T)
 de  de 
  
Line 310: Line 310:
  
 <code> <code>
-> de <- read.csv("http://commres.net/wiki/_media/detergent.csv", sep = ",", header=T)+> de <- read.csv("http://commres.net/_media/detergent.csv", sep = ",", header=T)
 > de  > de 
    type w.temp cleanness    type w.temp cleanness
Line 386: Line 386:
  
 만약에 손으로 계산했다면 R에서  만약에 손으로 계산했다면 R에서 
 +<tabbox rs.anova.detergent>
 <code> <code>
-de <- read.csv("http://commres.net/wiki/_media/detergent.csv", sep = ",", header=T)+de <- read.csv("http://commres.net/_media/detergent.csv", sep = ",", header=T)
 de  de 
  
Line 524: Line 525:
 summary(de.typenova) summary(de.typenova)
 </code> </code>
 +<tabbox ro.anova.detergent>
 +<code>
 +> de <- read.csv("http://commres.net/_media/detergent.csv", sep = ",", header=T)
 +> de 
 +   type w.temp cleanness
 +1          1         4
 +2          1         5
 +3          1         6
 +4          1         5
 +5          1         6
 +6          1         6
 +7          1         4
 +8          1         4
 +9          2         7
 +10    1      2         9
 +11    1      2         8
 +12    1      2        10
 +13    2      2        13
 +14    2      2        15
 +15    2      2        12
 +16    2      2        12
 +17    1      3        10
 +18    1      3        12
 +19    1      3        11
 +20    1      3         9
 +21    2      3        12
 +22    2      3        13
 +23    2      3        10
 +24    2      3        13
 +
 +> de$type <- factor(de$type, level=c(1,2), label=c("super", "best"))
 +> de$w.temp <- factor(de$w.temp, level=c(1,2,3), label=c("cold", "warm", "hot"))
 +> de
 +    type w.temp cleanness
 +1  super   cold         4
 +2  super   cold         5
 +3  super   cold         6
 +4  super   cold         5
 +5   best   cold         6
 +6   best   cold         6
 +7   best   cold         4
 +8   best   cold         4
 +9  super   warm         7
 +10 super   warm         9
 +11 super   warm         8
 +12 super   warm        10
 +13  best   warm        13
 +14  best   warm        15
 +15  best   warm        12
 +16  best   warm        12
 +17 super    hot        10
 +18 super    hot        12
 +19 super    hot        11
 +20 super    hot         9
 +21  best    hot        12
 +22  best    hot        13
 +23  best    hot        10
 +24  best    hot        13
 +
 +> de.typenova <- aov(cleanness ~ type * w.temp, data=de)
 +> summary(de.typenova)
 +            Df Sum Sq Mean Sq F value   Pr(>F)    
 +type             24   24.00   15.43 0.000986 ***
 +w.temp          193   96.50   62.04 8.41e-09 ***
 +type:w.temp  2     21   10.50    6.75 0.006496 ** 
 +Residuals   18     28    1.56                     
 +---
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +> with(de, interaction.plot(x.factor=type, 
 ++                           trace.factor=w.temp, response=cleanness, 
 ++                           fun=mean, type="b", legend=T,
 ++                           ylab="cleanness", main="Interaction Plot (type by temp)",
 ++                           pch=c(1,19)))
 +
 +> attach(de)
 +> table(type, w.temp)
 +       w.temp
 +type    cold warm hot
 +  super    4    4   4
 +  best        4   4
 +> n.sub <- length(cleanness)
 +> n.type.group <- 2
 +> n.w.temp.group <- 3
 +
 +> tapply(cleanness, list(type, w.temp), mean) # 각 셀에서의 평균
 +      cold warm  hot
 +super    5  8.5 10.5
 +best     5 13.0 12.0
 +> df.within.each <- tapply(cleanness, list(type, w.temp), length) -1  # 각 셀에서의 샘플숫자
 +> n.within.each <- df.within.each + 1
 +> df.within <- sum(df.within.each) # df within
 +
 +> var.within <- tapply(cleanness, list(type, w.temp), var) # var.within
 +> ss.within.each <- tapply(cleanness, list(type, w.temp), var) * df.within.each
 +> ss.within.each
 +      cold warm hot
 +super    2    5   5
 +best        6   6
 +> ss.within <- sum(ss.within.each) # ss.within
 +> ss.within
 +[1] 28
 +
 +
 +> interaction.plot(type, w.temp, cleanness)
 +
 +> mean.type <- tapply(cleanness, list(type), mean)
 +> mean.w.temp <- tapply(cleanness, list(w.temp), mean)
 +> mean.type
 +super  best 
 +    8    10 
 +> mean.w.temp
 + cold  warm   hot 
 + 5.00 10.75 11.25 
 +
 +> var.type <- tapply(cleanness, list(type), var)
 +> var.w.temp <- tapply(cleanness, list(w.temp), var)
 +
 +
 +> mean.tot <- mean(cleanness)
 +> var.tot <- var(cleanness)
 +> n.sub <- length(cleanness)
 +> df.tot <- n.sub - 1 
 +> ss.tot <- var.tot * df.tot
 +
 +> ## between
 +> mean.each <- tapply(cleanness, list(type, w.temp), mean)
 +> mean.each
 +      cold warm  hot
 +super    5  8.5 10.5
 +best     5 13.0 12.0
 +> mean.tot <- mean(cleanness)
 +> mean.tot
 +[1] 9
 +> n.each <- tapply(cleanness, list(type, w.temp), length)
 +> n.each
 +      cold warm hot
 +super    4    4   4
 +best        4   4
 +> n.type.each <- tapply(cleanness, list(type), length)
 +> n.w.temp.each <- tapply(cleanness, list(w.temp), length)
 +
 +> ss.w.bet <- sum(n.each*(mean.each-mean.tot)^2)
 +> ss.w.bet
 +[1] 238
 +
 +> ss.tot
 +[1] 266
 +> ss.within
 +[1] 28
 +> ss.w.bet
 +[1] 238
 +> ss.w.bet + ss.within
 +[1] 266
 +
 +> ss.type <- sum(n.type.each * ((mean.tot - mean.type)^2))
 +> ss.w.temp <- sum(n.w.temp.each * ((mean.tot - mean.w.temp)^2))
 +> ss.type
 +[1] 24
 +> ss.w.temp
 +[1] 193
 +> ss.type.w.temp <- ss.w.bet - (ss.type + ss.w.temp)
 +> ss.type.w.temp
 +[1] 21
 +
 +> ss.tot
 +[1] 266
 +> ss.w.bet
 +[1] 238
 +> ss.within
 +[1] 28
 +> ss.type
 +[1] 24
 +> ss.w.temp
 +[1] 193
 +> ss.type.w.temp
 +[1] 21
 +
 +> df.tot <- n.sub - 1
 +> df.w.bet <- (n.type.group * n.w.temp.group) - 1
 +> df.type <- n.type.group - 1
 +> df.w.temp <- n.w.temp.group - 1
 +> df.type.w.temp <- df.w.bet - (df.type + df.w.temp)
 +> df.within <- sum(df.within.each)
 +
 +> df.tot
 +[1] 23
 +> df.w.bet
 +[1] 5
 +> df.type
 +[1] 1
 +> df.w.temp
 +[1] 2
 +> df.type.w.temp
 +[1] 2
 +> df.within
 +[1] 18
 +
 +> ms.type <- ss.type / df.type
 +> ms.w.temp <- ss.w.temp / df.w.temp
 +> ms.type.w.temp <- ss.type.w.temp / df.type.w.temp
 +> ms.within <- ss.within / df.within
 +
 +> ms.type
 +[1] 24
 +> ms.w.temp
 +[1] 96.5
 +> ms.type.w.temp
 +[1] 10.5
 +> ms.within
 +[1] 1.555556
 +
 +
 +> f.type <- ms.type / ms.within
 +> f.w.temp <- ms.w.temp / ms.within
 +> f.type.w.temp <- ms.type.w.temp / ms.within
 +
 +> alpha <- .05
 +> # confidence interval
 +> ci <- 1 - alpha
 +
 +> f.type
 +[1] 15.42857
 +> # 봐야할 F분포표에서의 F-value
 +> # qt 처럼 qf 사용
 +> # qf(alpha, df.w.between, df.within, lower.tail=F) 처럼 사용
 +> qf(ci, df.type, df.within)
 +[1] 4.413873
 +> # 혹은 
 +> # qf(alpha, df.type, df.within, lower.tail = F)
 +> # 도 마찬가지
 +> pf(f.type, df.type, df.within, lower.tail = F)
 +[1] 0.0009861125
 +
 +> f.w.temp
 +[1] 62.03571
 +> qf(ci, df.w.temp, df.within)
 +[1] 3.554557
 +> pf(f.w.temp, df.w.temp, df.within, lower.tail = F)
 +[1] 8.411856e-09
 +
 +> f.type.w.temp
 +[1] 6.75
 +> qf(ci, df.type.w.temp, df.within)
 +[1] 3.554557
 +> pf(f.type.w.temp, df.type.w.temp, df.within, lower.tail = F)
 +[1] 0.006496173
 +
 +> # aov result
 +> summary(de.typenova)
 +            Df Sum Sq Mean Sq F value   Pr(>F)    
 +type             24   24.00   15.43 0.000986 ***
 +w.temp          193   96.50   62.04 8.41e-09 ***
 +type:w.temp  2     21   10.50    6.75 0.006496 ** 
 +Residuals   18     28    1.56                     
 +---
 +S
 +</code>
 +</tabbox>
  
 ===== 예 2.  cookie experiment ===== ===== 예 2.  cookie experiment =====
Line 615: Line 875:
  
 <code> <code>
-cookies <- read.csv("http://commres.net/wiki/_media/cookies.csv")+cookies <- read.csv("http://commres.net/_media/cookies.csv")
 cookies cookies
  
Line 637: Line 897:
  
 <code> <code>
-> cookies <- read.csv("http://commres.net/wiki/_media/cookies.csv")+> cookies <- read.csv("http://commres.net/_media/cookies.csv")
 > cookies > cookies
    weight fullness ncookies    weight fullness ncookies
Line 878: Line 1138:
 Build hypotheses. Use ANOVA with critical level = .05 to test the researcher's hypotheses. Build hypotheses. Use ANOVA with critical level = .05 to test the researcher's hypotheses.
  
 +see [[https://statsandr.com/blog/two-way-anova-in-r/]]
 ====== Materials and links ====== ====== Materials and links ======
   * {{:AnovaData.sav}}   * {{:AnovaData.sav}}
factorial_anova.1727133668.txt.gz · Last modified: by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki