repeated_measure_anova
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| repeated_measure_anova [2023/05/03 08:04] – [demo 2] hkimscil | repeated_measure_anova [2025/05/07 08:40] (current) – [Repeated Measure ANOVA] hkimscil | ||
|---|---|---|---|
| Line 79: | Line 79: | ||
| -- Picture about here -- | -- Picture about here -- | ||
| + | {{: | ||
| + | ---- | ||
| + | {{: | ||
| + | ---- | ||
| * but, $\text{SS}_\text{{within}}$ can be partitioned as | * but, $\text{SS}_\text{{within}}$ can be partitioned as | ||
| * $\text{SS}_{\text{ subjects}}$ and $\text{SS}_{\text{ error}}$ | * $\text{SS}_{\text{ subjects}}$ and $\text{SS}_{\text{ error}}$ | ||
| Line 101: | Line 104: | ||
| | **Grand mean: 45.9** | | **Grand mean: 45.9** | ||
| - | We do this (and the below example) with an excel {{: | + | We do this (and the below example) with an excel {{: |
| We also require {{: | We also require {{: | ||
| Line 258: | Line 261: | ||
| see {{: | see {{: | ||
| ===== demo 2 ===== | ===== demo 2 ===== | ||
| - | < | + | see [[: |
| - | # create data | + | ===== Twoway repeated measure anova===== |
| - | df <- data.frame(patient=rep(1:5, each=4), | + | see [[:r:twoway repeated measure anova]] |
| - | drug=rep(1:4, times=5), | + | |
| - | | + | |
| - | 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), | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | > #create 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 | ||
| - | > | ||
| - | > #within sujbect anova | ||
| - | > within.aov.mod <- aov(response~drug+Error(patient), | ||
| - | > | ||
| - | > | ||
| - | > summary(within.aov.mod) | ||
| - | |||
| - | Error: patient | ||
| - | Df Sum Sq Mean Sq F value Pr(>F) | ||
| - | Residuals | ||
| - | |||
| - | Error: Within | ||
| - | Df Sum Sq Mean Sq F value Pr(>F) | ||
| - | drug | ||
| - | Residuals 17 1412.6 | ||
| - | </ | ||
| - | The above is <fc # | ||
| - | < | ||
| - | within.aov.mod <- aov(response~factor(drug)+Error(factor(patient)), | ||
| - | |||
| - | summary(within.aov.mod) | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | > within.aov.mod <- aov(response~factor(drug)+Error(factor(patient)), | ||
| - | > | ||
| - | > | ||
| - | > summary(within.aov.mod) | ||
| - | |||
| - | Error: factor(patient) | ||
| - | Df Sum Sq Mean Sq F value Pr(>F) | ||
| - | Residuals | ||
| - | |||
| - | Error: Within | ||
| - | Df Sum Sq Mean Sq F value | ||
| - | factor(drug) | ||
| - | Residuals | ||
| - | --- | ||
| - | Signif. codes: | ||
| - | 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 | ||
| - | > | ||
| - | |||
| - | </ | ||
| - | ====== two way ====== | ||
| - | < | ||
| - | demo1 <- read.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, | ||
| - | ylim = c(5, 20), lty= c(1, 12), lwd = 3, | ||
| - | ylab = "mean of pulse", | ||
| - | |||
| - | demo1.aov <- aov(pulse ~ group * time + Error(id), data = demo1) | ||
| - | summary(demo1.aov) | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | > summary(demo1.aov) | ||
| - | |||
| - | Error: id | ||
| - | Df Sum Sq Mean Sq F value Pr(> | ||
| - | group 1 155.04 | ||
| - | Residuals | ||
| - | --- | ||
| - | Signif. codes: | ||
| - | |||
| - | Error: Within | ||
| - | Df Sum Sq Mean Sq F value Pr(>F) | ||
| - | time 2 0.0833 0.04167 | ||
| - | group: | ||
| - | Residuals | ||
| - | |||
| - | </ | ||
| - | {{: | ||
| - | |||
| - | ===== demo2 ===== | ||
| - | < | ||
| - | demo2 <- read.csv(" | ||
| - | ## Convert variables to factor | ||
| - | demo2 <- within(demo2, | ||
| - | group <- factor(group) | ||
| - | time <- factor(time) | ||
| - | id <- factor(id) | ||
| - | }) | ||
| - | demo2 | ||
| - | |||
| - | with(demo2, interaction.plot(time, | ||
| - | ylim = c(10, 40), lty = c(1, 12), lwd = 3, | ||
| - | ylab = "mean of pulse", | ||
| - | |||
| - | demo2.aov <- aov(pulse ~ group * time + Error(id), data = demo2) | ||
| - | summary(demo2.aov) | ||
| - | </ | ||
| - | |||
| - | {{: | ||
| - | |||
| - | < | ||
| - | > demo2 <- read.csv(" | ||
| - | > ## Convert variables to factor | ||
| - | > demo2 <- within(demo2, | ||
| - | + group <- factor(group) | ||
| - | + time <- factor(time) | ||
| - | + id <- factor(id) | ||
| - | + }) | ||
| - | |||
| - | > demo2 | ||
| - | id group pulse time | ||
| - | 1 | ||
| - | 2 | ||
| - | 3 | ||
| - | 4 | ||
| - | 5 | ||
| - | 6 | ||
| - | 7 | ||
| - | 8 | ||
| - | 9 | ||
| - | 10 4 | ||
| - | 11 4 | ||
| - | 12 4 | ||
| - | 13 5 | ||
| - | 14 5 | ||
| - | 15 5 | ||
| - | 16 6 | ||
| - | 17 6 | ||
| - | 18 6 | ||
| - | 19 7 | ||
| - | 20 7 | ||
| - | 21 7 | ||
| - | 22 8 | ||
| - | 23 8 | ||
| - | 24 8 | ||
| - | > | ||
| - | > with(demo2, interaction.plot(time, | ||
| - | + ylim = c(10, 40), lty = c(1, 12), lwd = 3, | ||
| - | + ylab = "mean of pulse", | ||
| - | > | ||
| - | > 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 | ||
| - | Residuals | ||
| - | |||
| - | Error: Within | ||
| - | Df Sum Sq Mean Sq F value | ||
| - | time 2 978.2 | ||
| - | group: | ||
| - | Residuals | ||
| - | --- | ||
| - | Signif. codes: | ||
| - | > | ||
| - | </ | ||
| - | ===== demo 3 ===== | ||
| - | < | ||
| - | demo3 <- read.csv(" | ||
| - | ## Convert variables to factor | ||
| - | demo3 <- within(demo3, | ||
| - | group <- factor(group) | ||
| - | time <- factor(time) | ||
| - | id <- factor(id) | ||
| - | }) | ||
| - | |||
| - | with(demo3, interaction.plot(time, | ||
| - | ylim = c(10, 60), lty = c(1, 12), lwd = 3, | ||
| - | ylab = "mean of pulse", | ||
| - | |||
| - | demo3.aov <- aov(pulse ~ group * time + Error(id), data = demo3) | ||
| - | summary(demo3.aov) | ||
| - | </ | ||
| - | |||
| - | {{: | ||
| - | |||
| - | < | ||
| - | > demo3 <- read.csv(" | ||
| - | > ## Convert variables to factor | ||
| - | > demo3 <- within(demo3, | ||
| - | + group <- factor(group) | ||
| - | + time <- factor(time) | ||
| - | + id <- factor(id) | ||
| - | + }) | ||
| - | > | ||
| - | > with(demo3, interaction.plot(time, | ||
| - | + ylim = c(10, 60), lty = c(1, 12), lwd = 3, | ||
| - | + ylab = "mean of pulse", | ||
| - | > | ||
| - | > demo3.aov <- aov(pulse ~ group * time + Error(id), data = demo3) | ||
| - | > summary(demo3.aov) | ||
| - | |||
| - | Error: id | ||
| - | Df Sum Sq Mean Sq F value Pr(> | ||
| - | group 1 2035.0 | ||
| - | Residuals | ||
| - | --- | ||
| - | Signif. codes: | ||
| - | |||
| - | Error: Within | ||
| - | Df Sum Sq Mean Sq F value | ||
| - | time 2 2830.3 | ||
| - | group: | ||
| - | Residuals | ||
| - | --- | ||
| - | Signif. codes: | ||
| - | > | ||
| - | > | ||
| - | |||
| - | </ | ||
| ====== reference ====== | ====== reference ====== | ||
| * [[http:// | * [[http:// | ||
repeated_measure_anova.1683068656.txt.gz · Last modified: by hkimscil
