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 [2015/10/13 11:46] – hkimscil | repeated_measure_anova [2024/05/01 08:27] (current) – hkimscil | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | See also, [[ANOVA]], [[: | + | See also, [[ANOVA]], [[: |
- | 설명이 불충분하므로, [[:Repeated Measure | + | ====== |
+ | Introduction | ||
+ | * one-way ANOVA for // | ||
+ | * extension of the dependent t-test (one group t-test, repeated measure t-test) | ||
+ | * also, it is called " | ||
+ | * the simplest one is __one-way repeated measures ANOVA__ | ||
+ | * which requires one independent and one dependent variable | ||
+ | * the independent variable is categorical (either nominal or ordinal) | ||
+ | * the dependent variable is continuous (interval or ratio) | ||
+ | |||
+ | Test Circumstances | ||
+ | * one subject with repeated measures across a time period (differences of mean scores across three or more time periods) | ||
+ | * participants being tested with headache drugs such as | ||
+ | * group A, B, C, placebo | ||
+ | * across the time periods j, k, l, m | ||
+ | * testing the effect of a three-month exercise training program on blood sugar level | ||
+ | * measure blood sugar level at 3 different points (pre-exercise, | ||
+ | * one subject with repeated measures in different situation (treatments; | ||
+ | * e.g., participant (n=30) using and evaluating three web site UI (naver, daum, and google) | ||
+ | * and rate its usefulness, usability and ease of use | ||
+ | * data should look as follows: | ||
+ | |||
+ | ^ ^ pre-excerise \\ "sugar level" | ||
+ | | | ||
+ | | b | 300 | 170 | 120 | | ||
+ | | c | 150 | 120 | 120 | | ||
+ | | d | 230 | 170 | 160 | | ||
+ | | e | 260 | 250 | 250 | | ||
+ | | | level 1 | level 2 | level 3 | | ||
+ | |||
+ | Levels = related groups of the independent variable " | ||
+ | |||
+ | ^ ^ treatment \\ condition \\ " | ||
+ | | a | 70 | 60 | 80 | | ||
+ | | b | 50 | 70 | 50 | | ||
+ | | c | 40 | 50 | 60 | | ||
+ | | d | 30 | 40 | 60 | | ||
+ | | e | 60 | 50 | 40 | | ||
+ | | | level 1 | level 2 | level 3 | | ||
+ | |||
+ | in general, the data should look | ||
+ | ^ ^ time/ | ||
+ | | | T1 | T2 | T3 | | ||
+ | | s1 | s1 | s1 | s1 | | ||
+ | | s2 | s2 | s2 | s2 | | ||
+ | | s3 | s3 | s3 | s3 | | ||
+ | | s4 | s4 | s4 | s4 | | ||
+ | | s5 | s5 | s5 | s5 | | ||
+ | | .. | .. | .. | .. | | ||
+ | | sn | sn | sn | sn | | ||
+ | |||
+ | You should discern the above from normal ANOVA situation. | ||
+ | |||
+ | ^ ^ group ^ treatment | ||
+ | | a | 1 | 70 | | ||
+ | | b | 1 | 50 | | ||
+ | | c | 1 | 40 | | ||
+ | | d | 1 | 30 | | ||
+ | | e | 1 | 60 | | ||
+ | | f | 2 | 60 | | ||
+ | | g | 2 | 70 | | ||
+ | | h | 2 | 50 | | ||
+ | | i | 2 | 40 | | ||
+ | | j | 2 | 50 | | ||
+ | | k | 3 | 80 | | ||
+ | | l | 3 | 50 | | ||
+ | | m | 3 | 60 | | ||
+ | | n | 3 | 60 | | ||
+ | | o | 3 | 40 | | ||
+ | |||
+ | LOGICS | ||
+ | * $\text{independent ANOVA: } F = \displaystyle \frac{MS_{between}}{MS_{within}} = \frac{MS_{between}}{MS_{error}}$ | ||
+ | |||
+ | * $\text{rep measures ANOVA: } F = \displaystyle \frac{MS_{between}}{MS_{within}} = \displaystyle \frac{MS_{conditions}}{MS_{error}}$ | ||
+ | |||
+ | 주> | ||
+ | * " | ||
+ | |||
+ | -- Picture about here -- | ||
+ | {{: | ||
+ | ---- | ||
+ | {{: | ||
+ | ---- | ||
+ | * but, $\text{SS}_\text{{within}}$ can be partitioned as | ||
+ | * $\text{SS}_{\text{ subjects}}$ and $\text{SS}_{\text{ error}}$ | ||
+ | * that is, some of the " | ||
+ | * Among the two, we can exclude the first from SS< | ||
+ | * and solely use the latter as SS< | ||
+ | * This is to say: | ||
+ | * in $\text{independent ANOVA: } \text{SS}_\text{{within}} = \text{SS}_{\text{error}} $ | ||
+ | * in $\text{rep measures ANOVA: } \text{SS}_\text{{within}} = \text{SS}_{\text{subjects}} + \text{SS}_{\text{error}}$ | ||
+ | * This means that the term SS< | ||
+ | * But, with this SS< | ||
+ | |||
+ | ^ subjects | ||
+ | | 1 | 45 | 50 | 55 | **50** | ||
+ | | 2 | 42 | 42 | 45 | **43** | ||
+ | | 3 | 36 | 41 | 43 | **40** | ||
+ | | 4 | 39 | 35 | 40 | **38** | ||
+ | | 5 | 51 | 55 | 59 | **55** | ||
+ | | 6 | 44 | 49 | 56 | **49.7** | ||
+ | | **Monthly mean** | ||
+ | | **Grand mean: 45.9** | ||
+ | |||
+ | We do this (and the below example) with an excel {{: | ||
+ | We also require {{: | ||
- | ====== Repeated Measures ANOVA ====== | ||
^ Headache Analysis | ^ Headache Analysis | ||
- | | || | + | | | base treatment |
- | | ser | w1 | w2 | w3 | w4 | w5 | $\overline{X}_{participants}$ = avePerCase | + | | ser | w1 | w2 | w3 | w4 | w5 | $\overline{X}_{part}$ \\ = average \\ per case \\ (subject, \\ participant) |
| 1 | 21 | 22 | 8 | 6 | 6 | 12.6 | | | 1 | 21 | 22 | 8 | 6 | 6 | 12.6 | | ||
| 2 | 20 | 19 | 10 | 4 | 9 | 12.4 | | | 2 | 20 | 19 | 10 | 4 | 9 | 12.4 | | ||
Line 15: | Line 119: | ||
| 8 | 13 | 4 | 8 | 1 | 5 | 6.2 | | | 8 | 13 | 4 | 8 | 1 | 5 | 6.2 | | ||
| 9 | 26 | 24 | 14 | 8 | 17 | 17.8 | | | 9 | 26 | 24 | 14 | 8 | 17 | 17.8 | | ||
- | | | + | | |
^ Stats ^^ | ^ Stats ^^ | ||
Line 24: | Line 128: | ||
| # of case (n) | 9 | | | # of case (n) | 9 | | ||
- | SS< | + | SS< |
- | SS< | + | |
- | SS< | + | SS< |
- | SS< | + | = SS< |
+ | = SS< | ||
+ | = $n\Sigma{(\overline{X}_{week} - \overline{X})^2}$ = 1934.5 \\ | ||
+ | |||
+ | SS< | ||
+ | = $ \Sigma \Sigma{(X_{s_i.t_j} - \overline{X_{t_j}})^2}$ | ||
+ | = $ \Sigma (411.6, 836.0, 78.0, 93.6, 135.6) $ | ||
+ | = 1554.7 | ||
+ | \\ | ||
+ | |||
+ | SS< | ||
+ | |||
+ | SS< | ||
= SS< | = SS< | ||
- | = SS< | + | = SS< |
+ | = 1554.7 | ||
= 721.1 | = 721.1 | ||
- | df< | + | OR |
+ | SS< | ||
+ | = SS< | ||
+ | = (SS< | ||
+ | = 721.1 \\ | ||
+ | \\ | ||
+ | df< | ||
df< | df< | ||
df< | df< | ||
Line 45: | Line 168: | ||
| C | 38 | 18 | 40 | | | C | 38 | 18 | 40 | | ||
| D | 45 | 32 | 43 | | | D | 45 | 32 | 43 | | ||
+ | ====== in r ====== | ||
+ | ===== demo1 ===== | ||
+ | [[https:// | ||
+ | <WRAP box info> | ||
+ | data files in e.gs: | ||
+ | {{: | ||
+ | {{: | ||
+ | {{: | ||
+ | {{: | ||
+ | {{: | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | 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) | ||
+ | </ | ||
+ | |||
+ | demo1 data는 아래와 같다. | ||
+ | < | ||
+ | id group pulse time | ||
+ | 1 1 10 1 | ||
+ | 1 1 10 2 | ||
+ | 1 1 10 3 | ||
+ | 2 1 10 1 | ||
+ | 2 1 10 2 | ||
+ | 2 1 10 3 | ||
+ | 3 1 10 1 | ||
+ | 3 1 10 2 | ||
+ | 3 1 10 3 | ||
+ | 4 1 10 1 | ||
+ | 4 1 10 2 | ||
+ | 4 1 10 3 | ||
+ | 5 2 15 1 | ||
+ | 5 2 15 2 | ||
+ | 5 2 15 3 | ||
+ | 6 2 15 1 | ||
+ | 6 2 15 2 | ||
+ | 6 2 15 3 | ||
+ | 7 2 16 1 | ||
+ | 7 2 15 2 | ||
+ | 7 2 15 3 | ||
+ | 8 2 15 1 | ||
+ | 8 2 15 2 | ||
+ | 8 2 15 3 | ||
+ | </ | ||
+ | 이를 정리해보면 | ||
+ | |||
+ | || || time |||||||| | ||
+ | || || t1 || t2 || t3 || mean \\ of the \\ same person' | ||
+ | || 1 || 10 || 10 || 10 || 10 || | ||
+ | || 2 || 10 || 10 || 10 || 10 || | ||
+ | || 3 || 10 || 10 || 10 || 10 || | ||
+ | || 4 || 10 || 10 || 10 || 10 || | ||
+ | || 5 || 15 || 15 || 15 || 15 || | ||
+ | || 6 || 15 || 15 || 15 || 15 || | ||
+ | || 7 || 16 || 15 || 15 || 15.333 | ||
+ | || 8 || 15 || 15 || 15 || 15 || | ||
+ | || mean \\ across \\ the time || 12.625 | ||
+ | |||
+ | |||
+ | < | ||
+ | demo1.within.only.aov <- aov(pulse ~ time + Error(id), data = demo1) | ||
+ | summary(demo1.within.only.aov) | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | > demo1.within.only.aov <- aov(pulse ~ time + Error(id), data = demo1) | ||
+ | > summary(demo1.within.only.aov) | ||
+ | |||
+ | Error: id | ||
+ | Df Sum Sq Mean Sq F value Pr(>F) | ||
+ | Residuals | ||
+ | |||
+ | Error: Within | ||
+ | Df Sum Sq Mean Sq F value Pr(>F) | ||
+ | time 2 0.0833 0.04167 | ||
+ | Residuals 14 0.5833 0.04167 | ||
+ | > | ||
+ | </ | ||
+ | |||
+ | see {{: | ||
+ | ===== demo 2 ===== | ||
+ | < | ||
+ | # create 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 | ||
+ | |||
+ | # 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:// | ||
Line 51: | Line 535: | ||
* http:// | * http:// | ||
* https:// | * https:// | ||
+ | |||
+ | * http:// | ||
repeated_measure_anova.1444706161.txt.gz · Last modified: 2015/10/13 11:46 by hkimscil