Emily Griffith SDQ with Time 1

library(arm)
## 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 /Users/levibrackman/Google Drive/R/Emily Griffith
library(lmerTest)
## 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
library(psych)
## 
## Attaching package: 'psych'
## 
## The following objects are masked from 'package:arm':
## 
##     logit, rescale, sim

data <- read.csv("EmilyGriffith_all.csv")
data$ID <- data$Q1

data <- data[data$Time > 1, ]
# Create scale scores
data$meanSDQ <- apply(data[, c("Q46_1", "Q46_2", "Q46_4", "Q46_5", "Q46_6", 
    "Q46_7", "Q46_8", "Q46_9", "Q46_10", "Q46_11")], 1, mean, na.rm = TRUE)
# Means or plotting
data$baseline <- ifelse(data$Time < 4, 0, 1)
pdata <- tapply(data[, "meanSDQ"], data[, 3], mean, na.rm = TRUE)
plot(pdata, type = "l")
M0 <- lmer(meanSDQ ~ 1 + (1 | ID), data = data)
fixef(M0)
## (Intercept) 
##       5.659
confint(M0)
## Computing profile confidence intervals ...
##              2.5 % 97.5 %
## .sig01      0.2969 0.7146
## .sigma      0.5133 0.7746
## (Intercept) 5.4600 5.8601
M1 <- update(M0, . ~ . + Time, REML = FALSE)
fixef(M1)
## (Intercept)        Time 
##      5.1009      0.2192
confint(M1)
## Computing profile confidence intervals ...
##               2.5 % 97.5 %
## .sig01      0.34519 0.7328
## .sigma      0.48129 0.7283
## (Intercept) 4.58990 5.6159
## Time        0.03173 0.4035
M2 <- update(M1, . ~ . + baseline)
fixef(M2)
## (Intercept)        Time    baseline 
##     5.46078     0.05787     0.42222
confint(M2)
## Computing profile confidence intervals ...
##               2.5 % 97.5 %
## .sig01       0.3592 0.7393
## .sigma       0.4699 0.7123
## (Intercept)  4.7389 6.1825
## Time        -0.2377 0.3525
## baseline    -0.1851 1.0234
M3 <- update(M2, . ~ . + I(Time^2))
## fixed-effect model matrix is rank deficient so dropping 1 column / coefficient
fixef(M3)
## (Intercept)        Time    baseline 
##     5.46078     0.05787     0.42222
confint(M3)
## Computing profile confidence intervals ...
##               2.5 % 97.5 %
## .sig01       0.3592 0.7393
## .sigma       0.4699 0.7123
## (Intercept)  4.7389 6.1825
## Time        -0.2377 0.3525
## baseline    -0.1851 1.0234

Pdata <- tapply(data[, "meanSDQ"], 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 = -0.1, max = 0.1)
## Warning: longer object length is not a multiple of shorter object length
## Error: replacement has 126 rows, data has 89
with(data, plot(TimeJIT, meanSDQ, col = "grey", pch = "*"))
## Error: object 'TimeJIT' not found
lines(pdata, col = "red", lwd = 2)

plot of chunk unnamed-chunk-1



You can also embed plots, for example:


```r
plot(cars)

plot of chunk unnamed-chunk-2