Repeated Measures for GRIT11 I have lots of reasons for living. (6) APPROACHING SIGNIFICANCE.
========================================================
#Loading the dataset that has been reset into a long version
data.test4 <- read.csv("/Volumes/TOSHIBA EXT/Dropbox/ADULT STUDY/adult_study011615.csv")
#Creating a new variable that is the mean of all positive purpose LET questions
library(reshape2); library(car)
## Warning: package 'car' was built under R version 3.1.2
data <- data.test4[,c("ID", "GROUP", "wave", "GRIT11")]
data <- dcast(data, ID + GROUP ~ wave, mean, value.var = "GRIT11")
data[,3:5] <- apply(data[,3:5],2,function(x) recode(x, "NaN = NA") )
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", "GRIT11", "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)
Load the psych package
library(psych)
##
## Attaching package: 'psych'
##
## The following object is masked from 'package:car':
##
## logit
Describe the LET 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 kurtosis
## BASELINE 1 86 4.51 0.73 5 4.66 0 2 5 3 -1.47 1.69
## GRIT11 2 59 4.63 0.64 5 4.76 0 3 5 2 -1.44 0.80
## se
## BASELINE 0.08
## GRIT11 0.08
## --------------------------------------------------------
## group: 1
## vars n mean sd median trimmed mad min max range skew
## BASELINE 1 88 4.20 1.04 4 4.42 1.48 1 5 4 -1.62
## GRIT11 2 54 4.46 0.64 5 4.55 0.00 3 5 2 -0.73
## kurtosis se
## BASELINE 2.24 0.11
## GRIT11 -0.54 0.09
Create a plot that visualizes LET 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(GRIT11 ~ BASELINE, data=data2)$residual
Plot the residuals to see that they are random
plot(density(residual))# A density plot
qqnorm(residual) # A quantile normal plot to checking normality
qqline(residual)
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$GRIT11))
sel2 <- which(!is.na(data2$BASELINE))
data2$residual[intersect(sel1,sel2)] <- residual
qplot(GROUP, GRIT11, data=data2, geom="boxplot")
## Warning: Removed 65 rows containing non-finite values (stat_boxplot).
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).
# Load the nlme package
library(nlme)
Two way repeated measures Graphing the Two-Way Interaction.
with(data2, boxplot(GRIT11 ~ WAVE + GROUP))
with(data2, boxplot(residual ~ WAVE + GROUP))
Comparing Basline to Wave 2 and 3 by Group.
fullModel <- lme(GRIT11 ~ GROUP * WAVE + BASELINE, random = ~1 | ID, data = data2, method = "ML", na.action = "na.omit")
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: Assesses whether the effects gets bigger between 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
## 170.1 189 -78.06
##
## Random effects:
## Formula: ~1 | ID
## (Intercept) Residual
## StdDev: 0.36 0.3746
##
## Fixed effects: GRIT11 ~ GROUP * WAVE + BASELINE
## Value Std.Error DF t-value p-value
## (Intercept) 2.3296 0.3581 66 6.505 0.0000
## GROUP1 0.1119 0.2520 66 0.444 0.6585
## WAVE 0.0978 0.1091 38 0.896 0.3759
## BASELINE 0.4728 0.0702 66 6.734 0.0000
## GROUP1:WAVE -0.1632 0.1598 38 -1.022 0.3134
## Correlation:
## (Intr) GROUP1 WAVE BASELI
## GROUP1 -0.418
## WAVE -0.396 0.593
## BASELINE -0.880 0.111 -0.028
## GROUP1:WAVE 0.330 -0.883 -0.681 -0.049
##
## Standardized Within-Group Residuals:
## Min Q1 Med Q3 Max
## -2.4861 -0.3073 0.1871 0.3618 1.6018
##
## Number of Observations: 109
## Number of Groups: 69
Table with P-values
| Value | Std.Error | DF | t-value | p-value | |
|---|---|---|---|---|---|
| (Intercept) | 2.3296 | 0.3581 | 66.0000 | 6.5053 | 0.0000 |
| GROUP1 | 0.1119 | 0.2520 | 66.0000 | 0.4439 | 0.6585 |
| WAVE | 0.0978 | 0.1091 | 38.0000 | 0.8960 | 0.3759 |
| BASELINE | 0.4728 | 0.0702 | 66.0000 | 6.7337 | 0.0000 |
| GROUP1:WAVE | -0.1632 | 0.1598 | 38.0000 | -1.0216 | 0.3134 |
``` Table with confidence intervals
| est. | lower | upper | |
|---|---|---|---|
| (Intercept) | 2.3296 | 1.6312 | 3.0280 |
| GROUP1 | 0.1119 | -0.3796 | 0.6034 |
| WAVE | 0.0978 | -0.1180 | 0.3136 |
| BASELINE | 0.4728 | 0.3359 | 0.6097 |
| GROUP1:WAVE | -0.1632 | -0.4792 | 0.1527 |