Title: Chicano Example Author: “Szu-Yu Chen” date: “02/10/2020” output: html_document


#Data

#Read Data

dta <- read.csv('C:/Users/ASUS/Desktop/data/Chicano.csv', stringsAsFactors = TRUE)

#Load pacman

pacman::p_load(tidyverse, VCA, lme4, nlme)

#Produce a variability chart (y=score, order x =Trt/Class/Pupil), labeling y axis as score,dusplay intercepts(mean) for each pupil in accordance with their “Class” &“Trt”( with salmon color)

VCA::varPlot(Score ~ Trt/Class/Pupil, 
             Data=dta,
             YLabel=list(text="Score", 
                         side=2, 
                         cex=1),
             MeanLine=list(var=c("Trt", "Class"),
                           col=c("darkred", "salmon"), 
                           lwd=c(1, 2)))

#Display a summary of residuals for within “class” and the whole model

summary(m1 <- aov(Score ~ Trt + Error(Class), data=dta))
## 
## Error: Class
##           Df Sum Sq Mean Sq F value Pr(>F)  
## Trt        1    216     216   9.818 0.0351 *
## Residuals  4     88      22                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Error: Within
##           Df Sum Sq Mean Sq F value Pr(>F)
## Residuals 18    198      11

#Derived “lmer” function from faraway package to get model and model fit information

faraway::sumary(m2 <- lmer(Score ~ Trt + (1 | Class), data=dta))
## Fixed Effects:
##             coef.est coef.se
## (Intercept) 4.00     1.35   
## TrtT        6.00     1.91   
## 
## Random Effects:
##  Groups   Name        Std.Dev.
##  Class    (Intercept) 1.66    
##  Residual             3.32    
## ---
## number of obs: 24, groups: Class, 6
## AIC = 130.9, DIC = 131.8
## deviance = 127.4

#compute bootstrap confidience intervals for m2 model

confint(m2, method="boot")
## Computing bootstrap confidence intervals ...
## 
## 117 message(s): boundary (singular) fit: see ?isSingular
##                2.5 %   97.5 %
## .sig01      0.000000 3.723490
## .sigma      2.237199 4.271600
## (Intercept) 1.296480 6.467043
## TrtT        2.627568 9.814294

The end