Emily Griffith Culture of Purpose Scale

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

data <- read.csv("EmilyGriffith_all.csv")

Creating School ID as ID

data$ID <- data$Q1

Create scale scores

key <- c(rep(1, 8), -1,-1)
data$meanCPS <- scoreItems(key, items = data[, grep("^CPS", names(data))], delete = FALSE)$score

Means or plotting

data$baseline <- ifelse(data$Time<4,0,1) 
pdata <- tapply(data[,"meanCPS"], data[,3], mean, na.rm=TRUE)
plot(pdata, type="l")

plot of chunk unnamed-chunk-6 Baseline Model

M0 <- lmer(meanCPS ~ 1 + (1|ID), data=data)
fixef(M0)
## (Intercept) 
##       5.191

Confidence Intervals

confint(M0)
## Computing profile confidence intervals ...
## Warning: convergence code 3 from bobyqa: bobyqa -- a trust region step
## failed to reduce q
##              2.5 % 97.5 %
## .sig01      0.0000 0.4945
## .sigma      0.5699 0.8043
## (Intercept) 5.0401 5.3382

Model 1

M1 <- update(M0, .~. + Time, REML=FALSE)
fixef(M1)
## (Intercept)        Time 
##      4.3798      0.3671

Confidence Intervals for Model 1

confint(M1)
## Computing profile confidence intervals ...
##              2.5 % 97.5 %
## .sig01      0.0000 0.4162
## .sigma      0.4991 0.7004
## (Intercept) 4.0886 4.6692
## Time        0.2495 0.4866

Model 2

M2 <- update(M1, .~. + baseline)
fixef(M2)
## (Intercept)        Time    baseline 
##      4.2147      0.4622     -0.4183

Conficence Intervals for Model 2

confint(M2)
## Computing profile confidence intervals ...
##               2.5 %  97.5 %
## .sig01       0.0000 0.41481
## .sigma       0.4907 0.68881
## (Intercept)  3.8738 4.55330
## Time         0.3059 0.62087
## baseline    -0.8785 0.04113

Model 3

M3 <- update(M2, .~. + I(Time^2))
fixef(M3)
## (Intercept)        Time    baseline   I(Time^2) 
##      3.2330      1.6023      0.5661     -0.2857

Confidence Intervals for Model 3

confint(M3)
## Computing profile confidence intervals ...
## Warning: convergence code 3 from bobyqa: bobyqa -- a trust region step
## failed to reduce q
##               2.5 %   97.5 %
## .sig01       0.0000  0.42012
## .sigma       0.4716  0.66248
## (Intercept)  2.3936  4.06625
## Time         0.7012  2.50800
## baseline    -0.3198  1.45199
## I(Time^2)   -0.5084 -0.06328
Pdata <- tapply(data[,"meanCPS"], data[,3], mean, na.rm=TRUE)
# Add random noise to time to better see the points of interest
data$TimeJIT <- data$Time+runif(126, min=-.1, max=.1)
with(data, plot(TimeJIT, meanCPS, col="grey", pch="*"))
lines(pdata, col="red", lwd=2)

plot of chunk unnamed-chunk-14 Intervention was given between 3 and 4 (Time 1 is not relevant because the data is not clean)

boxplot(data$meanCPS~Time, data=data, notch=F, col=(c("red","blue", "green","gold")), main="Culture of Purpose", xlab="Culture of Purpose", xlim = c(), ylim = c(3, 6.8 ), yaxs = "i")                                                                                                 

plot of chunk unnamed-chunk-15