r:repeated_measure_anova
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
r:repeated_measure_anova [2020/06/03 02:30] – created hkimscil | r:repeated_measure_anova [2024/05/08 08:23] (current) – [E.g. 2] hkimscil | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
+ | {{r: | ||
+ | < | ||
+ | ################################################### | ||
+ | ################################################### | ||
+ | ################################################### | ||
+ | # data | ||
+ | df <- data.frame(patient=rep(1: | ||
+ | | ||
+ | | ||
+ | 14, 18, 10, 22, | ||
+ | 24, 20, 18, 30, | ||
+ | 38, 34, 20, 44, | ||
+ | 26, 28, 14, 30)) | ||
+ | |||
+ | #view data | ||
+ | df | ||
+ | write.csv(df, | ||
+ | |||
+ | |||
+ | #fit repeated measures ANOVA model | ||
+ | df$drug <- factor(df$drug) | ||
+ | df$patient <- factor(df$patient) | ||
+ | |||
+ | # Error(patient) = patient error should be isolated | ||
+ | m.aov <- aov(response ~ drug | ||
+ | + Error(patient), | ||
+ | data = df) | ||
+ | #view model summary | ||
+ | summary(m.aov) | ||
+ | |||
+ | # check probability level (pr) | ||
+ | 1 - pf(24.75886525, | ||
+ | |||
+ | # A one-way repeated measures ANOVA was conducted | ||
+ | # on five individuals to examine the effect that | ||
+ | # four different drugs had on response time. | ||
+ | |||
+ | # Results showed that the type of drug used lead | ||
+ | # to statistically significant differences in | ||
+ | # response time (F(3, 12) = 24.76, p < 0.001). | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | > ################################################### | ||
+ | > ################################################### | ||
+ | > ################################################### | ||
+ | > | ||
+ | > # data | ||
+ | > df <- data.frame(patient=rep(1: | ||
+ | + drug=rep(1: | ||
+ | + response=c(30, | ||
+ | + 14, 18, 10, 22, | ||
+ | + 24, 20, 18, 30, | ||
+ | + 38, 34, 20, 44, | ||
+ | + 26, 28, 14, 30)) | ||
+ | > | ||
+ | > #view data | ||
+ | > df | ||
+ | | ||
+ | 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 | ||
+ | 11 | ||
+ | 12 | ||
+ | 13 | ||
+ | 14 | ||
+ | 15 | ||
+ | 16 | ||
+ | 17 | ||
+ | 18 | ||
+ | 19 | ||
+ | 20 | ||
+ | > write.csv(df, | ||
+ | > | ||
+ | > | ||
+ | > #fit repeated measures ANOVA model | ||
+ | > df$drug <- factor(df$drug) | ||
+ | > df$patient <- factor(df$patient) | ||
+ | > | ||
+ | > # Error(patient) = patient error should be isolated | ||
+ | > m.aov <- aov(response ~ drug | ||
+ | + + Error(patient), | ||
+ | + data = df) | ||
+ | > #view model summary | ||
+ | > summary(m.aov) | ||
+ | |||
+ | Error: patient | ||
+ | Df Sum Sq Mean Sq F value Pr(>F) | ||
+ | Residuals | ||
+ | |||
+ | Error: Within | ||
+ | Df Sum Sq Mean Sq F value | ||
+ | drug | ||
+ | Residuals 12 112.8 | ||
+ | --- | ||
+ | Signif. codes: | ||
+ | > | ||
+ | > # check probability level (pr) | ||
+ | > 1 - pf(24.75886525, | ||
+ | [1] 1.992501e-05 | ||
+ | > | ||
+ | > # A one-way repeated measures ANOVA was conducted | ||
+ | > # on five individuals to examine the effect that | ||
+ | > # four different drugs had on response time. | ||
+ | > | ||
+ | > # Results showed that the type of drug used lead | ||
+ | > # to statistically significant differences in | ||
+ | > # response time (F(3, 12) = 24.76, p < 0.001). | ||
+ | > | ||
+ | > | ||
+ | </ | ||
+ | ====== E.g. 2 ====== | ||
+ | {{: | ||
+ | < | ||
+ | # the second | ||
+ | movrev <- data.frame(reviewer=rep(1: | ||
+ | | ||
+ | | ||
+ | 76, 78, 90, | ||
+ | 78, 94, 95, | ||
+ | 80, 83, 88, | ||
+ | 82, 90, 99)) | ||
+ | |||
+ | #view data | ||
+ | movrev | ||
+ | write.csv(movrev, | ||
+ | |||
+ | movrev$movie <- factor(movrev$movie) | ||
+ | movrev$reviewer <- factor(movrev$reviewer) | ||
+ | |||
+ | # Error(reviewer) = reviewer error should be isolated | ||
+ | # The above is the same as Error(reviewer/ | ||
+ | m.aov <- aov(score ~ movie | ||
+ | + Error(reviewer), | ||
+ | data = movrev) | ||
+ | #view model summary | ||
+ | summary(m.aov) | ||
+ | |||
+ | # pairwise.t.test(movrev$score, | ||
+ | attach(movrev) | ||
+ | pairwise.t.test(score, | ||
+ | # or | ||
+ | with(movrev, | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | < | ||
+ | > # the second | ||
+ | > movrev <- data.frame(reviewer=rep(1: | ||
+ | + movie=rep(1: | ||
+ | + score=c(88, 84, 92, | ||
+ | + 76, 78, 90, | ||
+ | + 78, 94, 95, | ||
+ | + 80, 83, 88, | ||
+ | + 82, 90, 99)) | ||
+ | > | ||
+ | > #view data | ||
+ | > movrev | ||
+ | | ||
+ | 1 | ||
+ | 2 | ||
+ | 3 | ||
+ | 4 | ||
+ | 5 | ||
+ | 6 | ||
+ | 7 | ||
+ | 8 | ||
+ | 9 | ||
+ | 10 4 | ||
+ | 11 4 | ||
+ | 12 4 | ||
+ | 13 5 | ||
+ | 14 5 | ||
+ | 15 5 | ||
+ | > write.csv(movrev, | ||
+ | > | ||
+ | > movrev$movie <- factor(movrev$movie) | ||
+ | > movrev$reviewer <- factor(movrev$reviewer) | ||
+ | > | ||
+ | > # Error(reviewer) = reviewer error should be isolated | ||
+ | > # The above is the same as Error(reviewer/ | ||
+ | > m.aov <- aov(score ~ movie | ||
+ | + + Error(reviewer), | ||
+ | + data = movrev) | ||
+ | > #view model summary | ||
+ | > summary(m.aov) | ||
+ | |||
+ | Error: reviewer | ||
+ | Df Sum Sq Mean Sq F value Pr(>F) | ||
+ | Residuals | ||
+ | |||
+ | Error: Within | ||
+ | Df Sum Sq Mean Sq F value Pr(> | ||
+ | movie 2 363.3 181.67 | ||
+ | Residuals | ||
+ | --- | ||
+ | Signif. codes: | ||
+ | > | ||
+ | > # pairwise.t.test(movrev$score, | ||
+ | > attach(movrev) | ||
+ | The following objects are masked from movrev (pos = 5): | ||
+ | |||
+ | movie, reviewer, score | ||
+ | |||
+ | > pairwise.t.test(score, | ||
+ | |||
+ | Pairwise comparisons using paired t tests | ||
+ | |||
+ | data: score and movie | ||
+ | |||
+ | 1 | ||
+ | 2 0.628 - | ||
+ | 3 0.029 0.060 | ||
+ | |||
+ | P value adjustment method: bonferroni | ||
+ | > # or | ||
+ | > with(movrev, | ||
+ | + pairwise.t.test(score, | ||
+ | + paired = T, | ||
+ | + p.adjust.method = " | ||
+ | |||
+ | Pairwise comparisons using paired t tests | ||
+ | |||
+ | data: score and movie | ||
+ | |||
+ | 1 | ||
+ | 2 0.628 - | ||
+ | 3 0.029 0.060 | ||
+ | |||
+ | P value adjustment method: bonferroni | ||
+ | > | ||
+ | </ |
r/repeated_measure_anova.1591119039.txt.gz · Last modified: 2020/06/03 02:30 by hkimscil