User Tools

Site Tools


r:repeated_measure_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
r:repeated_measure_anova [2025/05/12 08:23] – [E.g. 2] hkimscilr:repeated_measure_anova [2025/05/12 08:25] (current) – [E.g.2 by hand] hkimscil
Line 298: Line 298:
 +              + Error(reviewer),  +              + Error(reviewer), 
 +              data = movrev) +              data = movrev)
 +> m2.aov <- aov(score ~ movie
 ++               + Error(reviewer/movie),
 ++               data = movrev)
 +
 > #view model summary > #view model summary
 > summary(m.aov) > summary(m.aov)
Line 310: Line 314:
 Residuals  8  142.7   17.83                    Residuals  8  142.7   17.83                   
 --- ---
-Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1+Signif. codes:   
 +0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
 +> summary(m2.aov) 
 + 
 +Error: reviewer 
 +          Df Sum Sq Mean Sq F value Pr(>F) 
 +Residuals  4  173.7   43.43                
 + 
 +Error: reviewer:movie 
 +          Df Sum Sq Mean Sq F value  Pr(>F)    
 +movie      2  363.3  181.67   10.19 0.00632 ** 
 +Residuals  8  142.7   17.83                    
 +--- 
 +Signif. codes:   
 +0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
  
 > # pairwise.t.test(movrev$score, movrev$movie, paired = T, p.adjust.method = "bonf") > # pairwise.t.test(movrev$score, movrev$movie, paired = T, p.adjust.method = "bonf")
 > attach(movrev) > attach(movrev)
-The following objects are masked from movrev (pos = 5):+The following objects are masked from movrev (pos = 12): 
 + 
 +    movie, reviewer, score 
 + 
 +The following objects are masked from movrev (pos = 14):
  
     movie, reviewer, score     movie, reviewer, score
Line 329: Line 351:
  
 P value adjustment method: bonferroni  P value adjustment method: bonferroni 
 +> detach(movrev)
 > # or > # or
 > with(movrev,  > with(movrev, 
Line 344: Line 367:
  
 P value adjustment method: bonferroni  P value adjustment method: bonferroni 
 +
 +
 +</code>
 +====== E.g.2 by hand ======
 +<code>
 +####
 +# by hand
 +####
 +movrev
 +tapply(movrev$score, list(reviewer, movie), mean) # 각 셀의 평균값
 +m.tot <- mean(movrev$score)
 +
 +
 +m.by.movie <- tapply(movrev$score, list(movie), mean)
 +m.by.er <- tapply(movrev$score, list(reviewer), mean)
 +
 +ss.bet <- sum(5*(m.tot-m.by.movie)^2)
 +df.bet <- 3-1 # 영화 가짓수 - 1
 +ms.bet <- ss.bet / df.bet
 +
 +var.by.movie <- tapply(movrev$score, list(movie), var)
 +ss.with <- sum(var.by.movie*4)
 +df.with <- 4 + 4 + 4
 +ms.with <- ss.with / df.with
 +ms.bet
 +ms.with
 +
 +ss.sub <- sum(3 * (m.tot-m.by.er)^2) # 3 treatments (movies)
 +df.sub <- 5 - 1 # 5 persons - 1
 +ms.sub <- ss.sub/df.sub
 +ms.sub
 +
 +ss.res <- ss.with - ss.sub
 +ss.res
 +df.res <- 4 * 2 # (N-1)*(k-1)
 +ms.res <- ss.res/df.res
 +ms.res
 +
 +f.cal <- ms.bet/ms.res
 +f.cal
 +pf(f.cal, 2, 8, lower.tail = F)
 +
 +ss.bet
 +ss.with
 +ss.sub
 +ss.res
 +df.bet
 +df.with
 +df.sub
 +df.res
 +ms.bet 
 +ms.with
 +ms.sub
 +ms.res
 +
 +# check
 +ss.with == ss.sub + ss.res
 +df.with == df.sub + df.res
 +summary(m.aov)
 +#
 +# no embedded
 +# understand the meaning of embedded
 +m0.aov <- aov(score ~ movie, data = movrev)
 +summary(m0.aov)
 +summary(m.aov)
 +
 +
 +</code>
 +
 +<code>
 +> ####
 +> # by hand
 +> ####
 +> movrev
 +   reviewer movie score
 +1                88
 +2                84
 +3                92
 +4                76
 +5                78
 +6                90
 +7                78
 +8                94
 +9                95
 +10        4        80
 +11        4        83
 +12        4        88
 +13        5        82
 +14        5        90
 +15        5        99
 +> tapply(movrev$score, list(reviewer, movie), mean) # 각 셀의 평균값
 +    2  3
 +1 88 84 92
 +2 76 78 90
 +3 78 94 95
 +4 80 83 88
 +5 82 90 99
 +> m.tot <- mean(movrev$score)
 +
 +
 +> m.by.movie <- tapply(movrev$score, list(movie), mean)
 +> m.by.er <- tapply(movrev$score, list(reviewer), mean)
 +
 +> ss.bet <- sum(5*(m.tot-m.by.movie)^2)
 +> df.bet <- 3-1 # 영화 가짓수 - 1
 +> ms.bet <- ss.bet / df.bet
 +
 +> var.by.movie <- tapply(movrev$score, list(movie), var)
 +> ss.with <- sum(var.by.movie*4)
 +> df.with <- 4 + 4 + 4
 +> ms.with <- ss.with / df.with
 +> ms.bet
 +[1] 181.6667
 +> ms.with
 +[1] 26.36667
 +
 +> ss.sub <- sum(3 * (m.tot-m.by.er)^2) # 3 treatments (movies)
 +> df.sub <- 5 - 1 # 5 persons - 1
 +> ms.sub <- ss.sub/df.sub
 +> ms.sub
 +[1] 43.43333
 +
 +> ss.res <- ss.with - ss.sub
 +> ss.res
 +[1] 142.6667
 +> df.res <- 4 * 2 # (N-1)*(k-1)
 +> ms.res <- ss.res/df.res
 +> ms.res
 +[1] 17.83333
 +
 +> f.cal <- ms.bet/ms.res
 +> f.cal
 +[1] 10.18692
 +> pf(f.cal, 2, 8, lower.tail = F)
 +[1] 0.006319577
 +
 +> ss.bet
 +[1] 363.3333
 +> ss.with
 +[1] 316.4
 +> ss.sub
 +[1] 173.7333
 +> ss.res
 +[1] 142.6667
 +> df.bet
 +[1] 2
 +> df.with
 +[1] 12
 +> df.sub
 +[1] 4
 +> df.res
 +[1] 8
 +> ms.bet 
 +[1] 181.6667
 +> ms.with
 +[1] 26.36667
 +> ms.sub
 +[1] 43.43333
 +> ms.res
 +[1] 17.83333
 +
 +> # check
 +> ss.with == ss.sub + ss.res
 +[1] TRUE
 +> df.with == df.sub + df.res
 +[1] TRUE
 +> summary(m.aov)
 +
 +Error: reviewer
 +          Df Sum Sq Mean Sq F value Pr(>F)
 +Residuals  4  173.7   43.43               
 +
 +Error: Within
 +          Df Sum Sq Mean Sq F value  Pr(>F)   
 +movie      2  363.3  181.67   10.19 0.00632 **
 +Residuals  8  142.7   17.83                   
 +---
 +Signif. codes:  
 +0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +> #
 +> # no embedded
 +> # understand the meaning of embedded
 +> m0.aov <- aov(score ~ movie, data = movrev)
 +> summary(m0.aov)
 +            Df Sum Sq Mean Sq F value Pr(>F)  
 +movie        2  363.3  181.67    6.89 0.0102 *
 +Residuals   12  316.4   26.37                 
 +---
 +Signif. codes:  
 +0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +> summary(m.aov)
 +
 +Error: reviewer
 +          Df Sum Sq Mean Sq F value Pr(>F)
 +Residuals  4  173.7   43.43               
 +
 +Error: Within
 +          Df Sum Sq Mean Sq F value  Pr(>F)   
 +movie      2  363.3  181.67   10.19 0.00632 **
 +Residuals  8  142.7   17.83                   
 +---
 +Signif. codes:  
 +0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +>
  
 </code> </code>
r/repeated_measure_anova.1747005805.txt.gz · Last modified: 2025/05/12 08:23 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki