1 Description

Conduct an analysis of the cognitive task example and commment on the results produced by each code chunk.

2 Input Data

dta8 <- read.table("cognitive_task.txt", h=T)
str(dta8)
## '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(dta8)
##    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

3 Plot

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

4 Data analysis

#Class as the random effects
m0 <- aov(Score ~ Method + Error(Class), data=dta8)

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
#Method as the random effects
m01 <- aov(Score ~ Method + Error(Method/Klass), data=dta8)

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
## random effect term: Class
m1 <- lme4::lmer(Score ~ Method + (1 | Class), data=dta8)
summary(m1)
## Linear mixed model fit by REML ['lmerMod']
## Formula: Score ~ Method + (1 | Class)
##    Data: dta8
## 
## 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
lme4::ranef(m1)
## $Class
##    (Intercept)
## C1   0.2389354
## C2  -1.6725478
## C3   1.9114833
## C4  -0.4778708
## C5  -0.2389354
## C6  -3.1061603
## C7   0.7168062
## C8   2.6282895
## 
## with conditional variances for "Class"
## random effect term: Method
m11 <- lme4::lmer(Score ~ Method + (1 | Method:Klass), data=dta8)
summary(m11)
## Linear mixed model fit by REML ['lmerMod']
## Formula: Score ~ Method + (1 | Method:Klass)
##    Data: dta8
## 
## 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
lme4::ranef(m11)
## $`Method:Klass`
##       (Intercept)
## I1:K1   0.2389354
## I1:K2  -1.6725478
## I1:K3   1.9114833
## I1:K4  -0.4778708
## I2:K1  -0.2389354
## I2:K2  -3.1061603
## I2:K3   0.7168062
## I2:K4   2.6282895
## 
## with conditional variances for "Method:Klass"
#computes confidence intervals for parameters in m1 by bootstrap
confint(m1, method="boot")
## Computing bootstrap confidence intervals ...
## 
## 1 message(s): boundary (singular) fit: see ?isSingular
##                 2.5 %   97.5 %
## .sig01      0.8734703 3.242560
## .sigma      0.6535771 1.121005
## (Intercept) 1.1862798 5.515181
## MethodI2    0.9172204 6.752496

5 The end