#Nested designs An experiment on a cognitive task was conducted. The design involved 4 classes nested within two methods of instruction. Thirty-two subjects were randomly assigned to one of the eight conditions. The score was the number of correct responses on the post-treatment test. Source: Kirk, R. (1982). Experimental Designs: Procedures for the Behavioral Sciences. p. 460.

#input data

dta <- read.table("C:/Users/Ching-Fang Wu/Documents/data/cognitive_task.txt", h=T)
str(dta)
## 'data.frame':    32 obs. of  5 variables:
##  $ ID    : chr  "S01" "S02" "S03" "S04" ...
##  $ Score : int  3 6 3 3 1 2 2 2 5 6 ...
##  $ Method: chr  "I1" "I1" "I1" "I1" ...
##  $ Class : chr  "C1" "C1" "C1" "C1" ...
##  $ Klass : chr  "K1" "K1" "K1" "K1" ...

#first 6 lines

head(dta)
##    ID Score Method Class Klass
## 1 S01     3     I1    C1    K1
## 2 S02     6     I1    C1    K1
## 3 S03     3     I1    C1    K1
## 4 S04     3     I1    C1    K1
## 5 S05     1     I1    C2    K2
## 6 S06     2     I1    C2    K2

1

VCA::varPlot(Score ~ Method/Class/ID, 
             Data=dta,
             YLabel=list(text="Score", side=2, cex=1),
             MeanLine=list(var=c("Method", "Class"),
                           col=c("darkred", "salmon"), lwd=c(1, 2)))
## Warning in min(x): min 中沒有無漏失的引數; 回傳 Inf
## Warning in max(x): max 中沒有無漏失的引數;回傳 -Inf

教學法2的平均分數高於教學法1

#ANOVA approach

m0 <- aov(Score ~ Method + Error(Class), data=dta)

2

m01 <- aov(Score ~ Method + Error(Method/Klass), data=dta)

3

summary(m0)
## 
## Error: Class
##           Df Sum Sq Mean Sq F value Pr(>F)  
## Method     1  112.5  112.50   6.459  0.044 *
## Residuals  6  104.5   17.42                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Error: Within
##           Df Sum Sq Mean Sq F value Pr(>F)
## Residuals 24   18.5  0.7708

4

summary(m01)
## 
## Error: Method
##        Df Sum Sq Mean Sq
## Method  1  112.5   112.5
## 
## Error: Method:Klass
##           Df Sum Sq Mean Sq F value Pr(>F)
## Residuals  6  104.5   17.42               
## 
## Error: Within
##           Df Sum Sq Mean Sq F value Pr(>F)
## Residuals 24   18.5  0.7708

#Mixed effect approach

m1 <- lme4::lmer(Score ~ Method + (1 | Class), data=dta)

#Mixed effect approach

m11 <- lme4::lmer(Score ~ Method + (1 | Method:Klass), data=dta)

5

confint(m1, method="boot")
## Computing bootstrap confidence intervals ...
##                 2.5 %   97.5 %
## .sig01      0.8273623 3.289616
## .sigma      0.6127138 1.105241
## (Intercept) 1.4981560 5.708186
## MethodI2    0.6890050 6.563107

6 The end