User Tools

Site Tools


r: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
r:repeated_measures_anova [2020/06/04 00:49] hkimscilr:repeated_measures_anova [2020/06/04 00:53] – [e.g. 3] hkimscil
Line 167: Line 167:
  
 </code> </code>
 +====== e.g. 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)
 +})
  
 +demo3
 +
 +par(cex = .6)
 +
 +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>
 +{{:r:pasted:20200604-005114.png}}
 +<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)
 ++ })
 +
 +> demo3
 +   id group pulse time
 +1          35    1
 +2          25    2
 +3          16    3
 +4          32    1
 +5          23    2
 +6          12    3
 +7          36    1
 +8          22    2
 +9          14    3
 +10  4        34    1
 +11  4        21    2
 +12  4        13    3
 +13  5        57    1
 +14  5        43    2
 +15  5        22    3
 +16  6        54    1
 +17  6        46    2
 +18  6        26    3
 +19  7        55    1
 +20  7        46    2
 +21  7        23    3
 +22  8        60    1
 +23  8        47    2
 +24  8        25    3
 +
 +> par(cex = .6)
 +
 +> 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>
 +
 +====== e.g. 4 ======
 +<code>
 +demo4 <- read.csv("https://stats.idre.ucla.edu/stat/data/demo4.csv")
 +## Convert variables to factor
 +demo4 <- within(demo4, {
 +  group <- factor(group)
 +  time <- factor(time)
 +  id <- factor(id)
 +})
 +
 +demo4
 +
 +par(cex = .6)
 +
 +with(demo4, interaction.plot(time, group, pulse,
 +  ylim = c(10, 60), lty = c(1, 12), lwd = 3,
 +  ylab = "mean of pulse", xlab = "time", trace.label = "group"))
 +
 +demo4.aov <- aov(pulse ~ group * time + Error(id), data = demo4)
 +summary(demo4.aov)
 +
 +</code>
 +
 +<code>
 +
 +> demo4 <- read.csv("https://stats.idre.ucla.edu/stat/data/demo4.csv")
 +> ## Convert variables to factor
 +> demo4 <- within(demo4, {
 ++     group <- factor(group)
 ++     time <- factor(time)
 ++     id <- factor(id)
 ++ })
 +
 +> demo4
 +   id group pulse time
 +1          35    1
 +2          25    2
 +3          12    3
 +4          34    1
 +5          22    2
 +6          13    3
 +7          36    1
 +8          21    2
 +9          18    3
 +10  4        35    1
 +11  4        23    2
 +12  4        15    3
 +13  5        31    1
 +14  5        43    2
 +15  5        57    3
 +16  6        35    1
 +17  6        46    2
 +18  6        58    3
 +19  7        37    1
 +20  7        48    2
 +21  7        51    3
 +22  8        32    1
 +23  8        45    2
 +24  8        53    3
 +
 +> par(cex = .6)
 +
 +> with(demo4, interaction.plot(time, group, pulse,
 ++                              ylim = c(10, 60), lty = c(1, 12), lwd = 3,
 ++                              ylab = "mean of pulse", xlab = "time", trace.label = "group"))
 +
 +> demo4.aov <- aov(pulse ~ group * time + Error(id), data = demo4)
 +> summary(demo4.aov)
 +
 +Error: id
 +          Df Sum Sq Mean Sq F value   Pr(>F)    
 +group      1 2542.0    2542     629 2.65e-07 ***
 +Residuals  6   24.3                           
 +---
 +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      1     0.5   0.079    0.925    
 +group:time  2   1736   868.2 137.079 5.44e-09 ***
 +Residuals  12     76     6.3                     
 +---
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +</code>
r/repeated_measures_anova.txt · Last modified: 2020/06/04 00:53 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki