User Tools

Site Tools


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
Last revisionBoth sides next revision
repeated_measure_anova [2023/05/01 00:15] hkimscilrepeated_measure_anova [2023/05/03 08:04] – [demo 2] hkimscil
Line 257: Line 257:
  
 see {{:r:repeated_measures_anova_eg.xlsx}} see {{:r:repeated_measures_anova_eg.xlsx}}
 +===== demo 2 =====
 +<code>
 +# create data
 +df <- data.frame(patient=rep(1:5, each=4),
 +                 drug=rep(1:4, times=5),
 +                 response=c(30, 28, 16, 34,
 +                            14, 18, 10, 22,
 +                            24, 20, 18, 30,
 +                            38, 34, 20, 44,
 +                            26, 28, 14, 30))
  
 +# view data
 +df
 +
 +# within sujbect anova
 +within.aov.mod <- aov(response~drug+Error(patient), data=df)
 +</code>
 +
 +<code>
 +> #create data
 +> df <- data.frame(patient=rep(1:5, each=4),
 ++                  drug=rep(1:4, times=5),
 ++                  response=c(30, 28, 16, 34,
 ++                             14, 18, 10, 22,
 ++                             24, 20, 18, 30,
 ++                             38, 34, 20, 44,
 ++                             26, 28, 14, 30))
 +
 +> #view data
 +> df
 +   patient drug response
 +1        1    1       30
 +2        1    2       28
 +3        1    3       16
 +4        1    4       34
 +5        2    1       14
 +6        2    2       18
 +7        2    3       10
 +8        2    4       22
 +9        3    1       24
 +10          2       20
 +11          3       18
 +12          4       30
 +13          1       38
 +14          2       34
 +15          3       20
 +16          4       44
 +17          1       26
 +18          2       28
 +19          3       14
 +20          4       30
 +
 +> #within sujbect anova
 +> within.aov.mod <- aov(response~drug+Error(patient), data=df)
 +
 +
 +> summary(within.aov.mod)
 +
 +Error: patient
 +          Df Sum Sq Mean Sq F value Pr(>F)
 +Residuals  1   67.6    67.6               
 +
 +Error: Within
 +          Df Sum Sq Mean Sq F value Pr(>F)
 +drug         11.6   11.56   0.139  0.714
 +Residuals 17 1412.6   83.10 
 +</code>
 +The above is <fc #ff0000>**WRONG**</fc>.
 +<code>
 +within.aov.mod <- aov(response~factor(drug)+Error(factor(patient)), data=df)
 +
 +summary(within.aov.mod)
 +</code>
 +
 +<code>
 +> within.aov.mod <- aov(response~factor(drug)+Error(factor(patient)), data=df)
 +
 +
 +> summary(within.aov.mod)
 +
 +Error: factor(patient)
 +          Df Sum Sq Mean Sq F value Pr(>F)
 +Residuals  4  680.8   170.2               
 +
 +Error: Within
 +             Df Sum Sq Mean Sq F value   Pr(>F)    
 +factor(drug)  3  698.2   232.7   24.76 1.99e-05 ***
 +Residuals    12  112.8     9.4                     
 +---
 +Signif. codes:  
 +0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +
 +</code>
 ====== two way ====== ====== two way ======
 <code> <code>
repeated_measure_anova.txt · Last modified: 2024/05/01 08:27 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki