MLQ Emily Griffith with Time1

setwd(“/Volumes/TOSHIBA EXT/Dropbox/Schools Study Data/Emily Griffith Data and R Scripts”)

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
data <- read.csv("EmilyGriffith_all.csv")
data$ID <- data$Q1
#Create scale scores
data$meanMLQ <- apply(data[, c("MLQ_1","MLQ_2","MLQ_3","MLQ_4","MLQ_5","MLQ_6", "MLQ_7", "MLQ_8", "MLQ_10")], 1, mean, na.rm = TRUE)
#Means or plotting
data$baseline <- ifelse(data$Time<4,0,1) 
pdata <- tapply(data[,"meanMLQ"], data[,3], mean, na.rm=TRUE)
plot(pdata, type="l")

plot of chunk unnamed-chunk-1

M0 <- lmer(meanMLQ ~ 1 + (1|ID), data=data)
fixef(M0)
## (Intercept) 
##       5.449
confint(M0)
## Computing profile confidence intervals ...
##              2.5 % 97.5 %
## .sig01      0.0000 0.6251
## .sigma      0.6769 0.9606
## (Intercept) 5.2685 5.6303
M1 <- update(M0, .~. + Time, REML=FALSE)
fixef(M1)
## (Intercept)        Time 
##     5.55073    -0.04638
confint(M1)
## 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.6226
## .sigma       0.6766 0.9607
## (Intercept)  5.1543 5.9479
## Time        -0.2078 0.1140
M2 <- update(M1, .~. + baseline)
fixef(M2)
## (Intercept)        Time    baseline 
##      5.7865     -0.1816      0.5937
confint(M2)
## 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.00000 0.63926
## .sigma       0.65742 0.93697
## (Intercept)  5.32268 6.25018
## Time        -0.39509 0.03179
## baseline    -0.03808 1.22146
M3 <- update(M2, .~. + I(Time^2))
fixef(M3)
## (Intercept)        Time    baseline   I(Time^2) 
##     6.30867    -0.78572     0.07464     0.15105
confint(M3)
## Computing profile confidence intervals ...
## 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
##               2.5 % 97.5 %
## .sig01       0.0000 0.6421
## .sigma       0.6527 0.9299
## (Intercept)  5.1327 7.4805
## Time        -2.0511 0.4841
## baseline    -1.1697 1.3179
## I(Time^2)   -0.1620 0.4629
Pdata <- tapply(data[,"meanMLQ"], 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, meanMLQ, col="grey", pch="*"))
lines(pdata, col="red", lwd=2)

plot of chunk unnamed-chunk-1

boxplot(data$meanMLQ~Time, data=data, notch=F, col=(c("red","blue", "green")), main="MLQ All", xlab="Academic Self Concept", xlim = c(), ylim = c(5, 6.8 ), yaxs = "i")                                                                                                 

plot of chunk unnamed-chunk-1