User Tools

Site Tools


repeated_measures_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
Last revisionBoth sides next revision
repeated_measures_anova [2018/10/30 08:15] hkimscilrepeated_measures_anova [2020/06/11 15:18] – [demo 3] hkimscil
Line 1: Line 1:
-See also, [[ANOVA]], [[:Factorial Anova|Factorial ANOVA]], [[:t-test#동일집단_간의_차이에_대해서_알아볼_때|paired sample t-test]] +See also, [[ANOVA]], [[:Factorial Anova|Factorial ANOVA]], [[:t-test#동일집단_간의_차이에_대해서_알아볼_때|paired sample t-test]] [[:r:repeated_measure_anova]]  
-====== Repeated Measures ANOVA ======+====== Repeated Measure ANOVA ======
 Introduction Introduction
   * one-way ANOVA for //**related, not-independent groups**//   * one-way ANOVA for //**related, not-independent groups**//
Line 145: Line 145:
 |  C  |  38  |  18  |  40  | |  C  |  38  |  18  |  40  |
 |  D  |  45  |  32  |  43  | |  D  |  45  |  32  |  43  |
 +====== in r ======
 +===== demo1 =====
  
 +[[https://rcompanion.org/handbook/I_09.html]] 
 +<WRAP box info>
 +data files in e.gs:
 +{{:demo1.csv}}
 +{{:demo2.csv}}
 +{{:demo3.csv}}
 +{{:demo4.csv}}
 +{{:exer.csv}}
 +</WRAP>
 +
 +<code>
 +demo1  <- read.csv("https://stats.idre.ucla.edu/stat/data/demo1.csv")
 +demo1 
 +str(demo1) ## 모든 변인이 int이므로 (숫자) factor로 바꿔야 한다
 +
 +## Convert variables to factor
 +demo1 <- within(demo1, {
 +  group <- factor(group)
 +  time <- factor(time)
 +  id <- factor(id)
 +}) ## 이제 pulse만 제외하고 모두 factor로 변환된 데이터
 +
 +str(demo1)
 +</code>
 +
 +demo1 data는 아래와 같다.
 +<code>
 +id group pulse time
 +1 1 10 1
 +1 1 10 2
 +1 1 10 3
 +2 1 10 1
 +2 1 10 2
 +2 1 10 3
 +3 1 10 1
 +3 1 10 2
 +3 1 10 3
 +4 1 10 1
 +4 1 10 2
 +4 1 10 3
 +5 2 15 1
 +5 2 15 2
 +5 2 15 3
 +6 2 15 1
 +6 2 15 2
 +6 2 15 3
 +7 2 16 1
 +7 2 15 2
 +7 2 15 3
 +8 2 15 1
 +8 2 15 2
 +8 2 15 3
 +</code>
 +이를 정리해보면 
 +
 +||   || time  ||||||||
 +||   || t1  || t2  || t3  || mean \\ of the \\ same person's \\ measures  ||
 +|| 1  || 10  || 10  || 10  || 10  ||
 +|| 2  || 10  || 10  || 10  || 10  ||
 +|| 3  || 10  || 10  || 10  || 10  ||
 +|| 4  || 10  || 10  || 10  || 10  ||
 +|| 5  || 15  || 15  || 15  || 15  ||
 +|| 6  || 15  || 15  || 15  || 15  ||
 +|| 7  || 16  || 15  || 15  || 15.333  ||
 +|| 8  || 15  || 15  || 15  || 15  ||
 +|| mean \\ across \\ the time  || 12.625  || 12.5  || 12.5  || 12.542  ||
 +
 +
 +<code>
 +demo1.within.only.aov <- aov(pulse ~ time + Error(id), data = demo1)
 +summary(demo1.within.only.aov)
 +</code>
 +
 +<code>
 +> demo1.within.only.aov <- aov(pulse ~ time + Error(id), data = demo1)
 +> summary(demo1.within.only.aov)
 +
 +Error: id
 +          Df Sum Sq Mean Sq F value Pr(>F)
 +Residuals  7  155.3   22.18               
 +
 +Error: Within
 +          Df Sum Sq Mean Sq F value Pr(>F)
 +time       2 0.0833 0.04167        0.393
 +Residuals 14 0.5833 0.04167               
 +
 +</code>
 +
 +<code>
 +demo1  <- read.csv("https://stats.idre.ucla.edu/stat/data/demo1.csv")
 +demo1 
 +str(demo1) ## 모든 변인이 int이므로 (숫자) factor로 바꿔야 한다
 +
 +## Convert variables to factor
 +demo1 <- within(demo1, {
 +  group <- factor(group)
 +  time <- factor(time)
 +  id <- factor(id)
 +}) ## 이제 pulse만 제외하고 모두 factor로 변환된 데이터
 +
 +str(demo1)
 +
 +par(cex = .6)
 +
 +with(demo1, interaction.plot(time, group, pulse,
 +  ylim = c(5, 20), lty= c(1, 12), lwd = 3,
 +  ylab = "mean of pulse", xlab = "time", trace.label = "group"))
 +
 +demo1.aov <- aov(pulse ~ group * time + Error(id), data = demo1)
 +summary(demo1.aov)
 +</code>
 +
 +<code>
 +> summary(demo1.aov)
 +
 +Error: id
 +          Df Sum Sq Mean Sq F value  Pr(>F)    
 +group      1 155.04  155.04    3721 1.3e-09 ***
 +Residuals  6   0.25    0.04                    
 +---
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +Error: Within
 +           Df Sum Sq Mean Sq F value Pr(>F)
 +time        2 0.0833 0.04167        0.397
 +group:time  2 0.0833 0.04167        0.397
 +Residuals  12 0.5000 0.04167               
 +
 +</code>
 +{{:pasted:20200611-142331.png?350}}
 +
 +===== demo2 =====
 +<code>
 +demo2 <- read.csv("https://stats.idre.ucla.edu/stat/data/demo2.csv")
 +## Convert variables to factor
 +demo2 <- within(demo2, {
 +    group <- factor(group)
 +    time <- factor(time)
 +    id <- factor(id)
 +})
 +demo2
 +
 +with(demo2, interaction.plot(time, group, pulse,
 + ylim = c(10, 40), lty = c(1, 12), lwd = 3,
 + ylab = "mean of pulse", xlab = "time", trace.label = "group"))
 +
 +demo2.aov <- aov(pulse ~ group * time + Error(id), data = demo2)
 +summary(demo2.aov)
 +</code>
 +
 +{{:pasted:20200611-151520.png?350}}
 +
 +<code>
 +> demo2 <- read.csv("https://stats.idre.ucla.edu/stat/data/demo2.csv")
 +> ## Convert variables to factor
 +> demo2 <- within(demo2, {
 ++     group <- factor(group)
 ++     time <- factor(time)
 ++     id <- factor(id)
 ++ })
 +
 +> demo2
 +   id group pulse time
 +1          14    1
 +2          19    2
 +3          29    3
 +4          15    1
 +5          25    2
 +6          26    3
 +7          16    1
 +8          16    2
 +9          31    3
 +10  4        12    1
 +11  4        24    2
 +12  4        32    3
 +13  5        10    1
 +14  5        21    2
 +15  5        24    3
 +16  6        17    1
 +17  6        26    2
 +18  6        35    3
 +19  7        19    1
 +20  7        22    2
 +21  7        32    3
 +22  8        15    1
 +23  8        23    2
 +24  8        34    3
 +
 +> with(demo2, interaction.plot(time, group, pulse,
 ++  ylim = c(10, 40), lty = c(1, 12), lwd = 3,
 ++  ylab = "mean of pulse", xlab = "time", trace.label = "group"))
 +
 +> demo2.aov <- aov(pulse ~ group * time + Error(id), data = demo2)
 +> summary(demo2.aov)
 +
 +Error: id
 +          Df Sum Sq Mean Sq F value Pr(>F)
 +group      1  15.04   15.04   0.836  0.396
 +Residuals  6 107.92   17.99               
 +
 +Error: Within
 +           Df Sum Sq Mean Sq F value   Pr(>F)    
 +time        2  978.2   489.1  53.684 1.03e-06 ***
 +group:time  2    1.1     0.5   0.059    0.943    
 +Residuals  12  109.3     9.1                     
 +---
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +</code>
 +===== demo 3 =====
 +<code>
 +demo3 <- read.csv("https://stats.idre.ucla.edu/stat/data/demo3.csv")
 +## Convert variables to factor
 +demo3 <- within(demo3, {
 +  group <- factor(group)
 +  time <- factor(time)
 +  id <- factor(id)
 +})
 +
 +with(demo3, interaction.plot(time, group, pulse,
 +  ylim = c(10, 60), lty = c(1, 12), lwd = 3,
 +  ylab = "mean of pulse", xlab = "time", trace.label = "group"))
 +
 +demo3.aov <- aov(pulse ~ group * time + Error(id), data = demo3)
 +summary(demo3.aov)
 +</code>
 +
 +{{:pasted:20200611-151755.png?350}}
 +
 +<code>
 +> demo3 <- read.csv("https://stats.idre.ucla.edu/stat/data/demo3.csv")
 +> ## Convert variables to factor
 +> demo3 <- within(demo3, {
 ++     group <- factor(group)
 ++     time <- factor(time)
 ++     id <- factor(id)
 ++ })
 +
 +> with(demo3, interaction.plot(time, group, pulse,
 ++  ylim = c(10, 60), lty = c(1, 12), lwd = 3,
 ++  ylab = "mean of pulse", xlab = "time", trace.label = "group"))
 +
 +> demo3.aov <- aov(pulse ~ group * time + Error(id), data = demo3)
 +> summary(demo3.aov)
 +
 +Error: id
 +          Df Sum Sq Mean Sq F value  Pr(>F)    
 +group      1 2035.0  2035.0   343.1 1.6e-06 ***
 +Residuals  6   35.6     5.9                    
 +---
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +Error: Within
 +           Df Sum Sq Mean Sq F value   Pr(>F)    
 +time        2 2830.3  1415.2   553.8 1.52e-12 ***
 +group:time  2  200.3   100.2    39.2 5.47e-06 ***
 +Residuals  12   30.7     2.6                     
 +---
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +
 +
 +</code>
 ====== reference ====== ====== reference ======
   * [[http://wwwstage.valpo.edu/other/dabook/ch12/c12-1.htm|Repeated measures one-way ANOVA]] by Akkelin   * [[http://wwwstage.valpo.edu/other/dabook/ch12/c12-1.htm|Repeated measures one-way ANOVA]] by Akkelin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki