``` Load Packages
library(arm); library(lmerTest); library(psych)
## Loading required package: MASS
## Loading required package: Matrix
## Loading required package: lme4
## Loading required package: Rcpp
##
## arm (Version 1.7-03, built: 2014-4-27)
##
## Working directory is /Volumes/TOSHIBA EXT/Dropbox/Schools Study Data/Emily Griffith Data and R Scripts
##
## KernSmooth 2.23 loaded
## Copyright M. P. Wand 1997-2009
##
## Attaching package: 'lmerTest'
##
## The following object is masked from 'package:lme4':
##
## lmer
##
## The following object is masked from 'package:stats':
##
## step
##
##
## Attaching package: 'psych'
##
## The following objects are masked from 'package:arm':
##
## logit, rescale, sim
Loading Data
setwd("/Volumes/TOSHIBA EXT/Dropbox/Schools Study Data/Emily Griffith Data and R Scripts")
data <- read.csv("EmilyGriffith_all.csv")
Creating School ID as ID
data$ID <- data$Q1
#Create scale scores
data$meanAPSI <- apply(data[, c("APSI_1", "APSI_2", "APSI_3", "APSI_4", "APSI_5",
"APSI_7", "APSI_8")], 1, mean, na.rm = TRUE)
#Means or plotting
data$baseline <- ifelse(data$Time<4,0,1)
pdata <- tapply(data[,"meanAPSI"], data[,3], mean, na.rm=TRUE)
plot(pdata, type="l")
M0 <- lmer(meanAPSI ~ 1 + (1|ID), data=data)
fixef(M0)
## (Intercept)
## 4.453
confint(M0)
## Computing profile confidence intervals ...
## Warning: non-monotonic profile
## 2.5 % 97.5 %
## .sig01 0.0000 Inf
## .sigma 0.9595 1.236
## (Intercept) 4.2560 4.650
M1 <- update(M0, .~. + Time, REML=FALSE)
fixef(M1)
## (Intercept) Time
## 5.580 -0.504
confint(M1)
## Computing profile confidence intervals ...
## Warning: slightly lower deviances (diff=-5.68434e-14) detected
## Warning: slightly lower deviances (diff=-5.68434e-14) detected
## Warning: Last two rows have identical or NA .zeta values: using minstep
## Warning: slightly lower deviances (diff=-5.68434e-14) detected
## Warning: slightly lower deviances (diff=-5.68434e-14) detected
## Warning: Last two rows have identical or NA .zeta values: using minstep
## Warning: slightly lower deviances (diff=-5.68434e-14) detected
## Warning: non-monotonic profile
## Warning: convergence code 3 from bobyqa: bobyqa -- a trust region step failed to reduce q
## Warning: convergence code 3 from bobyqa: bobyqa -- a trust region step failed to reduce q
## Warning: non-monotonic profile
## 2.5 % 97.5 %
## .sig01 0.0000 Inf
## .sigma 0.0000 Inf
## (Intercept) 5.1308 6.0300
## Time -0.6888 -0.3191
M2 <- update(M1, .~. + baseline)
fixef(M2)
## (Intercept) Time baseline
## 6.2028 -0.8628 1.5650
confint(M2)
## Computing profile confidence intervals ...
## 2.5 % 97.5 %
## .sig01 0.0000 0.4746
## .sigma 0.7531 1.0195
## (Intercept) 5.7080 6.6965
## Time -1.0931 -0.6322
## baseline 0.8832 2.2446
M3 <- update(M2, .~. + I(Time^2))
fixef(M3)
## (Intercept) Time baseline I(Time^2)
## 9.761 -4.944 -1.900 1.019
confint(M3)
## Computing profile confidence intervals ...
## 2.5 % 97.5 %
## .sig01 0.2742 0.6617
## .sigma 0.5407 0.7605
## (Intercept) 8.7307 10.7596
## Time -6.0098 -3.8399
## baseline -2.9417 -0.8316
## I(Time^2) 0.7473 1.2819
plots
Intervention was given between 3 and 4 (Time 1 is not relevant because that data is not clean)
boxplot(data$meanAPSI~Time, data=data, notch=F, col=(c("red","blue", "green", "gold")), main="Sense of Identity", xlab="Sense of Identity", xlim = c(), ylim = c(3, 8 ), yaxs = "i")