User Tools

Site Tools


twoway_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
twoway_repeated_measure_anova [2022/10/04 08:57] hkimsciltwoway_repeated_measure_anova [2023/04/30 23:36] (current) hkimscil
Line 29: Line 29:
  
 {{:pasted:20220510-102845.png}} {{:pasted:20220510-102845.png}}
 +
 +<code>
 +> acne <- read.csv("http://commres.net/wiki/_media/r/10_rmanova.csv")
 +> str(acne)
 +'data.frame': 14 obs. of  6 variables:
 + $ group : int  1 1 1 1 1 1 1 2 2 2 ...
 + $ id    : int  1 2 3 4 5 6 7 8 9 10 ...
 + $ month0: int  60 52 62 58 65 58 53 55 55 60 ...
 + $ month1: int  41 38 36 34 34 42 38 42 54 55 ...
 + $ month3: int  25 23 22 21 28 26 25 33 46 46 ...
 + $ month6: int  16 12 14 13 18 16 21 22 26 23 ...
 +> acne
 +   group id month0 month1 month3 month6
 +1      1  1     60     41     25     16
 +2      1  2     52     38     23     12
 +3      1  3     62     36     22     14
 +4      1  4     58     34     21     13
 +5      1  5     65     34     28     18
 +6      1  6     58     42     26     16
 +7      1  7     53     38     25     21
 +8      2  8     55     42     33     22
 +9      2  9     55     54     46     26
 +10     2 10     60     55     46     23
 +11     2 11     63     45     40     25
 +12     2 12     52     41     35     22
 +13     2 13     61     38     32     18
 +14     2 14     58     43     39     21
 +
 +> # install.packages("reshape")
 +> library(reshape)
 +Warning message:
 +패키지 ‘reshape’는 R 버전 4.1.3에서 작성되었습니다 
 +
 +> acne.re <- reshape(acne, direction="long", varying=3:6, sep="")
 +
 +> str(acne.re)
 +'data.frame': 56 obs. of  4 variables:
 + $ group: int  1 1 1 1 1 1 1 2 2 2 ...
 + $ id   : int  1 2 3 4 5 6 7 8 9 10 ...
 + $ time : num  0 0 0 0 0 0 0 0 0 0 ...
 + $ month: int  60 52 62 58 65 58 53 55 55 60 ...
 + - attr(*, "reshapeLong")=List of 4
 +  ..$ varying:List of 1
 +  .. ..$ month: chr [1:4] "month0" "month1" "month3" "month6"
 +  .. ..- attr(*, "v.names")= chr "month"
 +  .. ..- attr(*, "times")= num [1:4] 0 1 3 6
 +  ..$ v.names: chr "month"
 +  ..$ idvar  : chr "id"
 +  ..$ timevar: chr "time"
 +> acne.re$group <- factor(acne.re$group)
 +> acne.re$id <- factor(acne.re$id)
 +> acne.re$time <- factor(acne.re$time)
 +> str(acne.re)
 +'data.frame': 56 obs. of  4 variables:
 + $ group: Factor w/ 2 levels "1","2": 1 1 1 1 1 1 1 2 2 2 ...
 + $ id   : Factor w/ 14 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
 + $ time : Factor w/ 4 levels "0","1","3","6": 1 1 1 1 1 1 1 1 1 1 ...
 + $ month: int  60 52 62 58 65 58 53 55 55 60 ...
 + - attr(*, "reshapeLong")=List of 4
 +  ..$ varying:List of 1
 +  .. ..$ month: chr [1:4] "month0" "month1" "month3" "month6"
 +  .. ..- attr(*, "v.names")= chr "month"
 +  .. ..- attr(*, "times")= num [1:4] 0 1 3 6
 +  ..$ v.names: chr "month"
 +  ..$ idvar  : chr "id"
 +  ..$ timevar: chr "time"
 +
 +> acne.re
 +     group id time month
 +1.0      1  1    0    60
 +2.0      1  2    0    52
 +3.0      1  3    0    62
 +4.0      1  4    0    58
 +5.0      1  5    0    65
 +6.0      1  6    0    58
 +7.0      1  7    0    53
 +8.0      2  8    0    55
 +9.0      2  9    0    55
 +10.0     2 10    0    60
 +11.0     2 11    0    63
 +12.0     2 12    0    52
 +13.0     2 13    0    61
 +14.0     2 14    0    58
 +1.1      1  1    1    41
 +2.1      1  2    1    38
 +3.1      1  3    1    36
 +4.1      1  4    1    34
 +5.1      1  5    1    34
 +6.1      1  6    1    42
 +7.1      1  7    1    38
 +8.1      2  8    1    42
 +9.1      2  9    1    54
 +10.1     2 10    1    55
 +11.1     2 11    1    45
 +12.1     2 12    1    41
 +13.1     2 13    1    38
 +14.1     2 14    1    43
 +1.3      1  1    3    25
 +2.3      1  2    3    23
 +3.3      1  3    3    22
 +4.3      1  4    3    21
 +5.3      1  5    3    28
 +6.3      1  6    3    26
 +7.3      1  7    3    25
 +8.3      2  8    3    33
 +9.3      2  9    3    46
 +10.3     2 10    3    46
 +11.3     2 11    3    40
 +12.3     2 12    3    35
 +13.3     2 13    3    32
 +14.3     2 14    3    39
 +1.6      1  1    6    16
 +2.6      1  2    6    12
 +3.6      1  3    6    14
 +4.6      1  4    6    13
 +5.6      1  5    6    18
 +6.6      1  6    6    16
 +7.6      1  7    6    21
 +8.6      2  8    6    22
 +9.6      2  9    6    26
 +10.6     2 10    6    23
 +11.6     2 11    6    25
 +12.6     2 12    6    22
 +13.6     2 13    6    18
 +14.6     2 14    6    21
 +
 +> attach(acne.re)
 +The following objects are masked from acne.re (pos = 4):
 +
 +    group, id, month, time
 +
 +> acne.re.anova <- aov(month~group*time+Error(id/time), data=acne.re)
 +> summary(acne.re.anova)
 +
 +Error: id
 +          Df Sum Sq Mean Sq F value   Pr(>F)    
 +group      1  707.2   707.2   19.71 0.000808 ***
 +Residuals 12  430.6    35.9                     
 +---
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +Error: id:time
 +           Df Sum Sq Mean Sq F value  Pr(>F)    
 +time        3  11366    3789  308.78 < 2e-16 ***
 +group:time  3    396     132   10.77 3.4e-05 ***
 +Residuals  36    442      12                    
 +---
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +> interaction.plot(acne.re$time, acne.re$group, acne.re$month)
 +
 +</code>
twoway_repeated_measure_anova.txt · Last modified: 2023/04/30 23:36 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki