factorial_anova
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
factorial_anova [2019/02/20 21:45] – hkimscil | factorial_anova [2023/05/08 13:13] (current) – [Materials and links] hkimscil | ||
---|---|---|---|
Line 285: | Line 285: | ||
- Given that the between-treatments SS is equal to 100, what is the SS for the interaction? | - Given that the between-treatments SS is equal to 100, what is the SS for the interaction? | ||
- Calculate the within-treatments SS, df, and MS for these data. | - Calculate the within-treatments SS, df, and MS for these data. | ||
+ | ===== 예 1 ===== | ||
+ | {{detergent.csv}} | ||
+ | detergent 는 세탁의 정도를 세제의 종류와 물온도를 독립변인으로 (팩터로) 가설검증을 한 것이다. 데이터는 위의 {{detergent.csv}} 이다. 또한 손으로 Factorial ANOVA를 하기 위해 이 데이터를 엑셀에 정리하여 {{: | ||
- | ===== 예 ===== | + | < |
+ | de <- read.csv(" | ||
+ | de | ||
+ | |||
+ | de$type <- factor(de$type, | ||
+ | de$w.temp <- factor(de$w.temp, | ||
+ | de | ||
+ | |||
+ | de.anova <- aov(cleanness ~ type * w.temp, data=de) | ||
+ | summary(de.anova) | ||
+ | |||
+ | with(de, interaction.plot(x.factor=type, | ||
+ | trace.factor=w.temp, | ||
+ | fun=mean, type=" | ||
+ | ylab=" | ||
+ | pch=c(1, | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | < | ||
+ | > de <- read.csv(" | ||
+ | > de | ||
+ | type w.temp cleanness | ||
+ | 1 | ||
+ | 2 | ||
+ | 3 | ||
+ | 4 | ||
+ | 5 | ||
+ | 6 | ||
+ | 7 | ||
+ | 8 | ||
+ | 9 | ||
+ | 10 1 2 9 | ||
+ | 11 1 2 8 | ||
+ | 12 1 2 12 | ||
+ | 13 2 2 13 | ||
+ | 14 2 2 15 | ||
+ | 15 2 2 12 | ||
+ | 16 2 2 12 | ||
+ | 17 1 3 10 | ||
+ | 18 1 3 12 | ||
+ | 19 1 3 11 | ||
+ | 20 1 3 9 | ||
+ | 21 2 3 12 | ||
+ | 22 2 3 13 | ||
+ | 23 2 3 10 | ||
+ | 24 2 3 13 | ||
+ | > | ||
+ | > de$type <- factor(de$type, | ||
+ | > de$w.temp <- factor(de$w.temp, | ||
+ | > de | ||
+ | type w.temp cleanness | ||
+ | 1 super | ||
+ | 2 super | ||
+ | 3 super | ||
+ | 4 super | ||
+ | 5 | ||
+ | 6 | ||
+ | 7 | ||
+ | 8 | ||
+ | 9 super | ||
+ | 10 super | ||
+ | 11 super | ||
+ | 12 super | ||
+ | 13 best | ||
+ | 14 best | ||
+ | 15 best | ||
+ | 16 best | ||
+ | 17 super hot 10 | ||
+ | 18 super hot 12 | ||
+ | 19 super hot 11 | ||
+ | 20 super hot 9 | ||
+ | 21 best hot 12 | ||
+ | 22 best hot 13 | ||
+ | 23 best hot 10 | ||
+ | 24 best hot 13 | ||
+ | > | ||
+ | > de.anova <- aov(cleanness ~ type * w.temp, data=de) | ||
+ | > summary(de.anova) | ||
+ | Df Sum Sq Mean Sq F value | ||
+ | type | ||
+ | w.temp | ||
+ | type: | ||
+ | Residuals | ||
+ | --- | ||
+ | Signif. codes: | ||
+ | > | ||
+ | </ | ||
+ | |||
+ | {{: | ||
+ | |||
+ | 만약에 손으로 계산했다면 R에서 | ||
+ | < | ||
+ | pf(9.810810811, | ||
+ | pf(48.72972973, | ||
+ | pf(3.972972973, | ||
+ | |||
+ | |||
+ | </ | ||
+ | < | ||
+ | > pf(9.810810811, | ||
+ | [1] 0.00575844 | ||
+ | > pf(48.72972973, | ||
+ | [1] 5.439849e-08 | ||
+ | > pf(3.972972973, | ||
+ | [1] 0.03722434 | ||
+ | > | ||
+ | > </ | ||
+ | |||
+ | ===== 예 2. cookie experiment | ||
* {{: | * {{: | ||
Line 297: | Line 410: | ||
$SS_{total}=\Sigma{X^2}-\frac{G^2}{N}$ | $SS_{total}=\Sigma{X^2}-\frac{G^2}{N}$ | ||
$SS_{\text{between}}=\Sigma{\frac{T^2}{n}}-\frac{G^2}{N}$ | $SS_{\text{between}}=\Sigma{\frac{T^2}{n}}-\frac{G^2}{N}$ | ||
- | $SS_{within} | + | $SS_{\text{within}} = \Sigma{SS_{\text{each |
- | $df_{between} | + | $df_{\text{between}} = k - 1$ |
- | $df_{within} | + | $df_{\text{within}} = \Sigma{df_{each \; treatment}} $ |
$SS_{total} = SS_{between} + SS_{within}$ | $SS_{total} = SS_{between} + SS_{within}$ | ||
Line 341: | Line 454: | ||
* $SS_{within}$ | * $SS_{within}$ | ||
- | * $SS_{within} = \Sum{SS_{within}} = 1502 + 940 + 1062 + 1084 = 4588$ | + | * $SS_{within} = \Sigma{SS_{within}} = 1502 + 940 + 1062 + 1084 = 4588$ |
* $SS_{between}$ | * $SS_{between}$ | ||
* $SS_{between} = 5108 - 4588 = 520 $ | * $SS_{between} = 5108 - 4588 = 520 $ | ||
* $SS_A$ | * $SS_A$ | ||
* $SS_B$ | * $SS_B$ | ||
- | * $SS_{AxB}$ | + | * $SS_{\text{AxB}}$ |
MS | MS | ||
* $MS_{A}$ | * $MS_{A}$ | ||
* $MS_{B}$ | * $MS_{B}$ | ||
- | * $MS_{AxB}$ | + | * $MS_{\text{AxB}}$ |
* $MS_{Within}$ | * $MS_{Within}$ | ||
F-ratio | F-ratio | ||
* $F_{A}$ | * $F_{A}$ | ||
* $F_{B}$ | * $F_{B}$ | ||
- | * $F_{AxB}$ | + | * $F_{\text{AxB}}$ |
Tests of Between-Subjects Effects | Tests of Between-Subjects Effects | ||
Line 370: | Line 483: | ||
| a R Squared = .102 (Adjusted R Squared = .066) |||||| | | a R Squared = .102 (Adjusted R Squared = .066) |||||| | ||
- | < | + | 데이터 파일 |
- | > cookies | + | {{: |
- | > str(cookies) | + | 손으로 계산하기 |
- | </ | + | {{: |
+ | |||
+ | < | ||
+ | cookies <- read.csv(" | ||
+ | cookies | ||
+ | |||
+ | str(cookies) | ||
+ | |||
+ | cookies$weight = factor(cookies$weight, | ||
+ | cookies$fullness = factor(cookies$fullness, | ||
+ | |||
+ | str(cookies) | ||
+ | cookies | ||
+ | |||
+ | with(cookies, | ||
+ | trace.factor=weight, | ||
+ | fun=mean, type=" | ||
+ | ylab=" | ||
+ | pch=c(1, | ||
- | < | + | cookies.aov <- aov(ncookies ~ weight * fullness, data=cookies) |
- | > cookies$fullness <- factor(cookies$fullness) | + | summary(cookies.aov) |
</ | </ | ||
< | < | ||
- | > attach(cookies) | + | > cookies <- read.csv(" |
- | > cookies.aov <- aov(ncookies | + | > cookies |
+ | | ||
+ | 1 | ||
+ | 2 | ||
+ | 3 | ||
+ | 4 | ||
+ | 5 | ||
+ | 6 | ||
+ | 7 | ||
+ | 8 | ||
+ | 9 | ||
+ | 10 1 1 20 | ||
+ | 11 1 1 23 | ||
+ | 12 1 1 25 | ||
+ | 13 1 1 9 | ||
+ | 14 1 1 21 | ||
+ | 15 1 1 22 | ||
+ | 16 1 1 26 | ||
+ | 17 1 1 26 | ||
+ | 18 1 1 28 | ||
+ | 19 1 1 22 | ||
+ | 20 1 1 3 | ||
+ | 21 1 2 22 | ||
+ | 22 1 2 7 | ||
+ | 23 1 2 15 | ||
+ | 24 1 2 6 | ||
+ | 25 1 2 8 | ||
+ | 26 1 2 18 | ||
+ | 27 1 2 24 | ||
+ | 28 1 2 19 | ||
+ | 29 1 2 11 | ||
+ | 30 1 2 9 | ||
+ | 31 1 2 24 | ||
+ | 32 1 2 19 | ||
+ | 33 1 2 9 | ||
+ | 34 1 2 19 | ||
+ | 35 1 2 29 | ||
+ | 36 1 2 9 | ||
+ | 37 1 2 18 | ||
+ | 38 1 2 17 | ||
+ | 39 1 2 3 | ||
+ | 40 1 2 14 | ||
+ | 41 2 1 7 | ||
+ | 42 2 1 19 | ||
+ | 43 2 1 8 | ||
+ | 44 2 1 23 | ||
+ | 45 2 1 6 | ||
+ | 46 2 1 11 | ||
+ | 47 2 1 18 | ||
+ | 48 2 1 23 | ||
+ | 49 2 1 22 | ||
+ | 50 2 1 16 | ||
+ | 51 2 1 28 | ||
+ | 52 2 1 19 | ||
+ | 53 2 1 2 | ||
+ | 54 2 1 27 | ||
+ | 55 2 1 20 | ||
+ | 56 2 1 25 | ||
+ | 57 2 1 23 | ||
+ | 58 2 1 10 | ||
+ | 59 2 1 19 | ||
+ | 60 2 1 14 | ||
+ | 61 2 2 14 | ||
+ | 62 2 2 21 | ||
+ | 63 2 2 16 | ||
+ | 64 2 2 14 | ||
+ | 65 2 2 17 | ||
+ | 66 2 2 20 | ||
+ | 67 2 2 20 | ||
+ | 68 2 2 21 | ||
+ | 69 2 2 32 | ||
+ | 70 2 2 26 | ||
+ | 71 2 2 9 | ||
+ | 72 2 2 14 | ||
+ | 73 2 2 16 | ||
+ | 74 2 2 15 | ||
+ | 75 2 2 6 | ||
+ | 76 2 2 5 | ||
+ | 77 2 2 12 | ||
+ | 78 2 2 23 | ||
+ | 79 2 2 27 | ||
+ | 80 2 2 32 | ||
+ | > | ||
+ | > str(cookies) | ||
+ | ' | ||
+ | $ weight | ||
+ | $ fullness: int 1 1 1 1 1 1 1 1 1 1 ... | ||
+ | | ||
+ | > | ||
+ | > cookies$weight | ||
+ | > cookies$fullness = factor(cookies$fullness, | ||
+ | > | ||
+ | |||
+ | > str(cookies) | ||
+ | 'data.frame': | ||
+ | $ weight | ||
+ | $ fullness: Factor w/ 2 levels " | ||
+ | $ ncookies: int 15 17 32 12 34 27 13 24 41 20 ... | ||
+ | > | ||
+ | > cookies | ||
+ | | ||
+ | 1 normal | ||
+ | 2 normal | ||
+ | 3 normal | ||
+ | 4 normal | ||
+ | 5 normal | ||
+ | 6 normal | ||
+ | 7 normal | ||
+ | 8 normal | ||
+ | 9 normal | ||
+ | 10 normal | ||
+ | 11 normal | ||
+ | 12 normal | ||
+ | 13 normal | ||
+ | 14 normal | ||
+ | 15 normal | ||
+ | 16 normal | ||
+ | 17 normal | ||
+ | 18 normal | ||
+ | 19 normal | ||
+ | 20 normal | ||
+ | 21 normal | ||
+ | 22 normal | ||
+ | 23 normal | ||
+ | 24 normal | ||
+ | 25 normal | ||
+ | 26 normal | ||
+ | 27 normal | ||
+ | 28 normal | ||
+ | 29 normal | ||
+ | 30 normal | ||
+ | 31 normal | ||
+ | 32 normal | ||
+ | 33 normal | ||
+ | 34 normal | ||
+ | 35 normal | ||
+ | 36 normal | ||
+ | 37 normal | ||
+ | 38 normal | ||
+ | 39 normal | ||
+ | 40 normal | ||
+ | 41 obese empty 7 | ||
+ | 42 obese empty 19 | ||
+ | 43 obese empty 8 | ||
+ | 44 obese empty 23 | ||
+ | 45 obese empty 6 | ||
+ | 46 obese empty 11 | ||
+ | 47 obese empty 18 | ||
+ | 48 obese empty 23 | ||
+ | 49 obese empty 22 | ||
+ | 50 obese empty 16 | ||
+ | 51 obese empty 28 | ||
+ | 52 obese empty 19 | ||
+ | 53 obese empty 2 | ||
+ | 54 obese empty 27 | ||
+ | 55 obese empty 20 | ||
+ | 56 obese empty 25 | ||
+ | 57 obese empty 23 | ||
+ | 58 obese empty 10 | ||
+ | 59 obese empty 19 | ||
+ | 60 obese empty 14 | ||
+ | 61 obese | ||
+ | 62 obese | ||
+ | 63 obese | ||
+ | 64 obese | ||
+ | 65 obese | ||
+ | 66 obese | ||
+ | 67 obese | ||
+ | 68 obese | ||
+ | 69 obese | ||
+ | 70 obese | ||
+ | 71 obese | ||
+ | 72 obese | ||
+ | 73 obese | ||
+ | 74 obese | ||
+ | 75 obese | ||
+ | 76 obese | ||
+ | 77 obese | ||
+ | 78 obese | ||
+ | 79 obese | ||
+ | 80 obese | ||
+ | > | ||
+ | |||
+ | > with(cookies, | ||
+ | + trace.factor=weight, | ||
+ | + fun=mean, type=" | ||
+ | + ylab=" | ||
+ | + pch=c(1,19))) | ||
+ | > | ||
</ | </ | ||
+ | {{: | ||
< | < | ||
+ | > cookies.aov <- aov(ncookies ~ weight * fullness, data=cookies) | ||
> summary(cookies.aov) | > summary(cookies.aov) | ||
- | + | | |
- | | + | weight |
- | weight | + | fullness |
- | fullness | + | weight: |
- | weight: | + | Residuals |
- | Residuals | + | |
- | | + | |
- | weight | + | |
- | fullness | + | |
- | weight: | + | |
- | Residuals | + | |
--- | --- | ||
- | Signif. codes: | + | Signif. codes: |
- | 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 | + | |
> | > | ||
</ | </ | ||
- | |||
- | |||
===== Interpreting interaction ===== | ===== Interpreting interaction ===== | ||
+ | 위에서 두개 독립변인에 대한 주효과가 없었으므로 각 독립변인의 종류 (특성) 별로 어디에서 차이가 났는가를 살피는 것은 의미가 없음. 따라서 아래는 필요한 절차가 아님. | ||
< | < | ||
Tukey multiple comparisons of means | Tukey multiple comparisons of means | ||
Line 451: | Line 764: | ||
- | {{tag>factorial anova, | + | {{tag>factorial_anova |
factorial_anova.1550666727.txt.gz · Last modified: 2019/02/20 21:45 by hkimscil