LET- Life Engagement Test (Scheier et al., 2006)

Repeated Measures for Life Engagement, w/ all questions (reverse coded)

#Loading the dataset that has been reset into a long version
data.test4 <- read.csv("/Volumes/TOSHIBA EXT/Dropbox/ADULT STUDY/adult_study011615.csv")
# Load the psych package
library(psych)

Creating a new variable that is the mean of all positive purpose meanLET questions

items <- c("LET1", "LET2", "LET3", "LET4", "LET5", "LET6")
scaleKey <- c(-1, 1, -1,1,-1,1)
data.test4$meanLET  <- scoreItems(scaleKey, items=data.test4[,items], delete=FALSE)$score
library(reshape2); library(car)
## Warning: package 'car' was built under R version 3.1.2
## 
## Attaching package: 'car'
## 
## The following object is masked from 'package:psych':
## 
##     logit
data <- data.test4[,c("ID", "GROUP", "wave", "meanLET")]
data <- dcast(data, ID + GROUP ~ wave, mean, value.var = "meanLET")
data[,3:5] <- apply(data[,3:5],2,function(x) recode(x, "NaN = NA") )

Create new data set with ID Group baseline meanLET and wave so that we have Baseline, time 1 and 2 to compare to

data2 <- as.data.frame(mapply(c,data[,1:4], data[,c(1:3,5)]))
data2$wave <- rep(1:2, each=89)
names(data2) <- c("ID", "GROUP", "BASELINE", "meanLET", "WAVE")

Drop the cases where participants did not complete the intervention completely

#data2 <- data2[-c(which(data2$GROUP ==2)),]

Intention to treat model (ITT) where we keep the cases who dropped out and did not complete the study (http://en.wikipedia.org/wiki/Intention-to-treat_analysis).

data2[which(data2$GROUP ==2), "GROUP"] <- 1

For lme to work GROUP and ID need to be seen as factors

data2$GROUP <-as.factor(data2$GROUP)
data2$ID <-as.factor(data2$ID)

Describe the meanLET variable by the GROUP variable

describeBy(data2[,3:4], group = data2$GROUP)
## group: 0
##          vars  n mean   sd median trimmed  mad  min max range  skew
## BASELINE    1 86 3.82 0.70   3.83    3.83 0.74 2.50   5  2.50 -0.23
## meanLET     2 59 4.05 0.81   4.17    4.14 0.74 1.83   5  3.17 -0.86
##          kurtosis   se
## BASELINE    -0.90 0.08
## meanLET     -0.03 0.11
## -------------------------------------------------------- 
## group: 1
##          vars  n mean   sd median trimmed  mad  min max range  skew
## BASELINE    1 88 3.59 0.86   3.58    3.60 0.86 2.00   5  3.00 -0.09
## meanLET     2 54 4.20 0.72   4.25    4.29 0.74 2.17   5  2.83 -0.98
##          kurtosis   se
## BASELINE    -0.98 0.09
## meanLET      0.49 0.10

Create a plot that visualizes meanLET variable by the GROUP variable

library(ggplot2)
## 
## Attaching package: 'ggplot2'
## 
## The following object is masked from 'package:psych':
## 
##     %+%

Take a look at the residuals

residual <- lm(meanLET ~ BASELINE, data=data2)$residual

Plot the residuals to see that they are random

plot(density(residual))# A density plot

plot of chunk unnamed-chunk-10

qqnorm(residual) # A quantile normal plot to checking normality
qqline(residual)

plot of chunk unnamed-chunk-10 Checking the different between intervention and control groups residuals. This allows us to control for individual unsystematic differences.

data2$residual <- NA
sel1 <- which(!is.na(data2$meanLET)) 
sel2 <- which(!is.na(data2$BASELINE))
data2$residual[intersect(sel1,sel2)] <- residual
qplot(GROUP, meanLET, data=data2, geom="boxplot")
## Warning: Removed 65 rows containing non-finite values (stat_boxplot).

plot of chunk unnamed-chunk-11 Plot of the difference between intervention and control groups.

qplot(GROUP, residual, data=data2, geom="boxplot")
## Warning: Removed 69 rows containing non-finite values (stat_boxplot).

plot of chunk unnamed-chunk-12 Two way repeated measures ======================================================== Graphing the Two-Way Interaction. Both meanLET and the Residuals

# Load the nlme package
library(nlme)
with(data2, boxplot(meanLET ~ WAVE + GROUP))

plot of chunk unnamed-chunk-13

with(data2, boxplot(residual ~ WAVE + GROUP))

plot of chunk unnamed-chunk-13

Linear Mixed-Effects Model

Comparing Basline to Wave 2 and 3 by Group.

fullModel <- lme(meanLET ~ GROUP * WAVE + BASELINE, random = ~1 | ID, data = data2, method = "ML", na.action = "na.omit")
Results

Explanation of significance:

We asses the significance of our models by comparing them from the baseline model using the anova() function.
(Intercept): Where everything is 0
GROUP1: Is there a difference between group. If it is significant than there is a difference and the treatment had an effect.
WAVE: Asseses whether the effects gets bigger beteen time 2 and 3 (does not have to be significant)
BASELINE: Should not be significant. If it is then it shows that there is a difference between groups before the treatment.
GROUP1:WAVE: If this is significant then it means that the effect was either fleeting or it happened after the treatment i.e. between time 2 and 3.

summary(fullModel)
## Linear mixed-effects model fit by maximum likelihood
##  Data: data2 
##     AIC   BIC logLik
##   168.1 186.9 -77.03
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept) Residual
## StdDev:       0.376   0.3594
## 
## Fixed effects: meanLET ~ GROUP * WAVE + BASELINE 
##               Value Std.Error DF t-value p-value
## (Intercept)  1.2053    0.3373 66   3.573  0.0007
## GROUP1      -0.0244    0.2443 66  -0.100  0.9209
## WAVE        -0.0946    0.1054 38  -0.897  0.3754
## BASELINE     0.7536    0.0773 66   9.755  0.0000
## GROUP1:WAVE  0.2525    0.1540 38   1.639  0.1094
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.384                     
## WAVE        -0.387  0.590              
## BASELINE    -0.871  0.060 -0.048       
## GROUP1:WAVE  0.273 -0.871 -0.684  0.024
## 
## Standardized Within-Group Residuals:
##      Min       Q1      Med       Q3      Max 
## -3.33870 -0.39783  0.03128  0.43784  1.96358 
## 
## Number of Observations: 109
## Number of Groups: 69

Table with P-values

Value Std.Error DF t-value p-value
(Intercept) 1.2053 0.3373 66.0000 3.5730 0.0007
GROUP1 -0.0244 0.2443 66.0000 -0.0997 0.9209
WAVE -0.0946 0.1054 38.0000 -0.8969 0.3754
BASELINE 0.7536 0.0773 66.0000 9.7546 0.0000
GROUP1:WAVE 0.2525 0.1540 38.0000 1.6393 0.1094

``` Table with confidence intervals

est. lower upper
(Intercept) 1.2053 0.5474 1.8632
GROUP1 -0.0244 -0.5009 0.4522
WAVE -0.0946 -0.3030 0.1139
BASELINE 0.7536 0.6029 0.9042
GROUP1:WAVE 0.2525 -0.0521 0.5571