1 input data

dta <- read.table("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" ...
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

2 Variability Chart for Hierarchical Models

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

結果圖顯示method l1平均分數低於l2。
class c1至c8的平均分數落於2至10分,具有明顯的變異

3 analysis

3.1 aov approach

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

#鑲嵌在 Klass 中的 Method error
m01 <- aov(Score ~ Method + Error(Method/Klass), data=dta)

#
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
#
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
#未鑲嵌在 Klass 中的 Method error
m02 <- aov(Score ~ Method + Error(Method), data=dta)
summary(m02)
## 
## Error: Method
##        Df Sum Sq Mean Sq
## Method  1  112.5   112.5
## 
## Error: Within
##           Df Sum Sq Mean Sq F value Pr(>F)
## Residuals 30    123     4.1

method 對分數的變異量112.5,且不同的方法其平均分數有顯著差異(p=0.044)
class 對分數的變異量104.5
個人間分數變異量18.5

m0和m01兩個model結果相同
Error(Method/Klass)與Error(class)意義相同

3.2 mixed effect approach 

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

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

#
summary(m1)
## Linear mixed model fit by REML ['lmerMod']
## Formula: Score ~ Method + (1 | Class)
##    Data: dta
## 
## REML criterion at convergence: 101.6
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.3028 -0.8416 -0.0126  0.3150  2.5753 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Class    (Intercept) 4.1615   2.040   
##  Residual             0.7708   0.878   
## Number of obs: 32, groups:  Class, 8
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)    3.500      1.043   3.355
## MethodI2       3.750      1.475   2.542
## 
## Correlation of Fixed Effects:
##          (Intr)
## MethodI2 -0.707
#
summary(m11)
## Linear mixed model fit by REML ['lmerMod']
## Formula: Score ~ Method + (1 | Method:Klass)
##    Data: dta
## 
## REML criterion at convergence: 101.6
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.3028 -0.8416 -0.0126  0.3150  2.5753 
## 
## Random effects:
##  Groups       Name        Variance Std.Dev.
##  Method:Klass (Intercept) 4.1615   2.040   
##  Residual                 0.7708   0.878   
## Number of obs: 32, groups:  Method:Klass, 8
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)    3.500      1.043   3.355
## MethodI2       3.750      1.475   2.542
## 
## Correlation of Fixed Effects:
##          (Intr)
## MethodI2 -0.707
#
confint(m1, method="boot")
## Computing bootstrap confidence intervals ...
##                 2.5 %   97.5 %
## .sig01      0.8170788 3.241563
## .sigma      0.6094929 1.129447
## (Intercept) 1.4478796 5.640406
## MethodI2    0.8609712 6.887529
# The end

m1與m11的結果相同。

score的截距為3.5
method l2的fix effect為3.75

class/Method:Klass random effect 4.16, residual 0.77

MethodI2 95CI:0.856~6.766