c:ms:2023:w07_anova_note
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
c:ms:2023:w07_anova_note [2023/04/18 20:43] – [Post hoc] hkimscil | c:ms:2023:w07_anova_note [2023/06/04 21:38] (current) – [Post hoc test] hkimscil | ||
---|---|---|---|
Line 125: | Line 125: | ||
</ | </ | ||
- | ====== Output | + | |
+ | ===== ANOVA in R: Output ===== | ||
< | < | ||
> # | > # | ||
Line 417: | Line 418: | ||
> | > | ||
</ | </ | ||
- | ====== R square or Eta ====== | + | |
+ | ====== Post hoc test ====== | ||
+ | [[:post hoc test]] | ||
+ | < | ||
+ | m.a | ||
+ | m.b | ||
+ | m.c | ||
+ | |||
+ | d.ab <- m.a - m.b | ||
+ | d.ac <- m.a - m.c | ||
+ | d.bc <- m.b - m.c | ||
+ | |||
+ | d.ab | ||
+ | d.ac | ||
+ | d.bc | ||
+ | |||
+ | # mse (ms within) from the a.res.sum output | ||
+ | # a.res.sum == summary(aov(values ~ group, data=comb3)) | ||
+ | a.res.sum | ||
+ | # mse = 50 | ||
+ | mse <- 50 | ||
+ | # 혹은 fansy way from comb3 data.frame | ||
+ | # 15 는 각 그룹의 df | ||
+ | sse.ch <- sum(tapply(comb3$values, | ||
+ | sse.ch | ||
+ | mse.ch <- sse.ch/45 | ||
+ | mse.ch | ||
+ | |||
+ | se <- sqrt(mse/ | ||
+ | |||
+ | # now t scores for two compared groups | ||
+ | t.ab <- d.ab / se | ||
+ | t.ac <- d.ac / se | ||
+ | t.bc <- d.bc / se | ||
+ | |||
+ | t.ab | ||
+ | t.ac | ||
+ | t.bc | ||
+ | |||
+ | # 이제 위의 점수를 .05 레벨에서 비교할 점수를 찾아 비교한다 | ||
+ | # qtukey 펑션을 이용한다 | ||
+ | t.crit <- qtukey( .95, nmeans = 3, df = 45) | ||
+ | t.crit | ||
+ | |||
+ | # t.ac만이 큰 것을 알 수 있다. | ||
+ | # 따라서 a 와 c 가 서로 다른 그룹 | ||
+ | # 즉, 1학년과 3학년이 서로 다른 그룹 | ||
+ | |||
+ | # 혹은 R이 보통 제시한 거꾸로 방법으로 보면 | ||
+ | ptukey(t.ab, | ||
+ | ptukey(t.ac, | ||
+ | ptukey(t.bc, | ||
+ | |||
+ | TukeyHSD(a.res, | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | plot(TukeyHSD(a.res, | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | pairwise.t.test(comb3$values, | ||
+ | </ | ||
+ | ===== post hoc test: output ===== | ||
+ | < | ||
+ | > m.a | ||
+ | [1] 26 | ||
+ | > m.b | ||
+ | [1] 24 | ||
+ | > m.c | ||
+ | [1] 19 | ||
+ | > | ||
+ | > d.ab <- m.a - m.b | ||
+ | > d.ac <- m.a - m.c | ||
+ | > d.bc <- m.b - m.c | ||
+ | > | ||
+ | > d.ab | ||
+ | [1] 2 | ||
+ | > d.ac | ||
+ | [1] 7 | ||
+ | > d.bc | ||
+ | [1] 5 | ||
+ | > | ||
+ | > # se | ||
+ | > # from the a.res.sum output | ||
+ | > a.res.sum | ||
+ | Df Sum Sq Mean Sq F value Pr(> | ||
+ | group 2 416 | ||
+ | Residuals | ||
+ | --- | ||
+ | Signif. codes: | ||
+ | > # mse = 50 | ||
+ | > mse <- 50 | ||
+ | > | ||
+ | > se <- sqrt(mse/ | ||
+ | > | ||
+ | > # now t scores for two compared groups | ||
+ | > t.ab <- d.ab / se | ||
+ | > t.ac <- d.ac / se | ||
+ | > t.bc <- d.bc / se | ||
+ | > | ||
+ | > t.ab | ||
+ | [1] 1.131371 | ||
+ | > t.ac | ||
+ | [1] 3.959798 | ||
+ | > t.bc | ||
+ | [1] 2.828427 | ||
+ | > | ||
+ | > # 이제 위의 점수를 .05 레벨에서 비교할 점수를 찾아 비교한다 | ||
+ | > # qtukey 펑션을 이용한다 | ||
+ | > t.crit <- qtukey( .95, nmeans = 3, df = 45) | ||
+ | > t.crit | ||
+ | [1] 3.427507 | ||
+ | > | ||
+ | > # t.ac만이 큰 것을 알 수 있다. | ||
+ | > # 따라서 a 와 c 가 서로 다른 그룹 | ||
+ | > # 즉, 1학년과 3학년이 서로 다른 그룹 | ||
+ | > | ||
+ | > # 혹은 R이 보통 제시한 거꾸로 방법으로 보면 | ||
+ | > ptukey(t.ab, | ||
+ | [1] 0.7049466 | ||
+ | > ptukey(t.ac, | ||
+ | [1] 0.02012498 | ||
+ | > ptukey(t.bc, | ||
+ | [1] 0.123877 | ||
+ | > | ||
+ | > TukeyHSD(a.res, | ||
+ | Tukey multiple comparisons of means | ||
+ | 95% family-wise confidence level | ||
+ | |||
+ | Fit: aov(formula = values ~ group, data = comb3) | ||
+ | |||
+ | $group | ||
+ | diff lwr | ||
+ | b-a | ||
+ | c-a -7 -13.059034 -0.940966 0.0201250 | ||
+ | c-b -5 -11.059034 | ||
+ | |||
+ | </ | ||
+ | |||
+ | {{: | ||
+ | ====== R square or Eta square | ||
SS toal | SS toal | ||
* = Y 변인만으로 Y를 예측했을 때의 오차의 제곱 | * = Y 변인만으로 Y를 예측했을 때의 오차의 제곱 | ||
Line 439: | Line 581: | ||
즉, IV로 uncertainty 가 얼마나 없어질까? | 즉, IV로 uncertainty 가 얼마나 없어질까? | ||
- | ====== | + | 이를 살펴보기 위해 |
- | [[:post hoc test]] | + | |
+ | < | ||
+ | ss.tot | ||
+ | ss.bet | ||
+ | r.sq <- ss.bet / ss.tot | ||
+ | r.sq | ||
+ | |||
+ | # then . . . . | ||
+ | |||
+ | lm.res <- lm(values ~ group, data = comb3) | ||
+ | summary(lm.res) | ||
+ | anova(lm.res) | ||
+ | </ | ||
+ | |||
+ | ===== R square: output | ||
+ | < | ||
+ | > ss.tot | ||
+ | [1] 2666 | ||
+ | > ss.bet | ||
+ | [1] 416 | ||
+ | > r.sq <- ss.bet / ss.tot | ||
+ | > r.sq | ||
+ | [1] 0.156039 | ||
+ | > | ||
+ | > # then . . . . | ||
+ | > | ||
+ | > lm.res <- lm(values ~ group, data = comb3) | ||
+ | > summary(lm.res) | ||
+ | |||
+ | Call: | ||
+ | lm(formula = values ~ group, data = comb3) | ||
+ | |||
+ | Residuals: | ||
+ | Min 1Q Median | ||
+ | -16.020 | ||
+ | |||
+ | Coefficients: | ||
+ | Estimate Std. Error t value Pr(> | ||
+ | (Intercept) | ||
+ | groupb | ||
+ | groupc | ||
+ | --- | ||
+ | Signif. codes: | ||
+ | |||
+ | Residual standard error: 7.071 on 45 degrees of freedom | ||
+ | Multiple R-squared: | ||
+ | F-statistic: | ||
+ | |||
+ | > anova(lm.res) | ||
+ | Analysis of Variance Table | ||
+ | |||
+ | Response: values | ||
+ | Df Sum Sq Mean Sq F value Pr(> | ||
+ | group 2 416 | ||
+ | Residuals 45 | ||
+ | --- | ||
+ | Signif. codes: | ||
+ | > | ||
+ | > | ||
+ | </ | ||
c/ms/2023/w07_anova_note.1681818202.txt.gz · Last modified: 2023/04/18 20:43 by hkimscil