Loading the dataset

setwd("~/Dropbox/ADULT STUDY")
data.test4 <- read.csv("adult_study011615.csv")
# Load the psych package
library(psych)
items <- c("PERMA1", "PERMA6", "PERMA12")
scaleKey <- c(1, 1, 1)
data.test4$meanPERMA  <- scoreItems(scaleKey, items=data.test4[,items], delete=FALSE)$score

library(reshape2); library(car); library(Amelia);library(mitools);library(nlme);library(predictmeans)
## 
## Attaching package: 'car'
## 
## The following object is masked from 'package:psych':
## 
##     logit
## 
## Loading required package: Rcpp
## ## 
## ## Amelia II: Multiple Imputation
## ## (Version 1.7.3, built: 2014-11-14)
## ## Copyright (C) 2005-2015 James Honaker, Gary King and Matthew Blackwell
## ## Refer to http://gking.harvard.edu/amelia/ for more information
## ## 
## Loading required package: lme4
## Loading required package: Matrix
## 
## Attaching package: 'lme4'
## 
## The following object is masked from 'package:nlme':
## 
##     lmList
#Remove the meanPERMA and ID Group and wave from dtat.test4 and create a new #dataset with only those variables.
data <- data.test4[,c("ID", "GROUP", "wave", "meanPERMA")]
#Use dcast to cnage from long-format data to wide format data
data <- dcast(data, ID + GROUP ~ wave, mean, value.var = "meanPERMA")
# Changing all NaNs to NA
data[,3:5] <- apply(data[,3:5],2,function(x) recode(x, "NaN = NA") )

Unsing the mapply function we create a new data set with ID Group baseline meanPERMA and wave 2 and 3 of meanPERMA. So we have a Baseline, which is Time 1 (placed in column 3 one on top of the other) to compare to both Time 2 and 3 (placed in column 4 one on top of the other). In the next line of code we then create a separate column called “wave” which calls the first 89 (which compares Time 2 to Baseline) “wave 1” and then the second 89 we call “wave 2” which compares Time 3 to Baseline. In the third line of code we add names to the new columns of the dataset.

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", "meanPERMA", "WAVE")

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). This line of data makes Group 2 become Group 1 so that Group 2 which were the people who dropped out become Group 1 i.e. part of the treatment group.

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

Make GROUP and ID a factor

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

Imputing missing data. 50 datasets are created.

MI <- amelia(data2, 50, idvars = c("ID"), ords = "GROUP")
## -- Imputation 1 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 2 --
## 
##   1  2  3  4  5  6  7  8  9 10 11
## 
## -- Imputation 3 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 4 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 5 --
## 
##   1  2  3  4  5  6  7  8  9 10
## 
## -- Imputation 6 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 7 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 8 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 9 --
## 
##   1  2  3  4  5  6  7  8  9 10
## 
## -- Imputation 10 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 11 --
## 
##   1  2  3  4  5  6  7  8  9 10 11
## 
## -- Imputation 12 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 13 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 14 --
## 
##   1  2  3  4  5  6  7  8  9 10 11
## 
## -- Imputation 15 --
## 
##   1  2  3  4  5  6  7  8  9 10
## 
## -- Imputation 16 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 17 --
## 
##   1  2  3  4  5  6  7  8  9 10 11
## 
## -- Imputation 18 --
## 
##   1  2  3  4  5  6  7  8  9 10
## 
## -- Imputation 19 --
## 
##   1  2  3  4  5  6  7  8  9 10 11 12
## 
## -- Imputation 20 --
## 
##   1  2  3  4  5  6  7  8  9 10 11
## 
## -- Imputation 21 --
## 
##   1  2  3  4  5  6  7  8  9 10 11
## 
## -- Imputation 22 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 23 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 24 --
## 
##   1  2  3  4  5  6  7  8  9 10 11 12
## 
## -- Imputation 25 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 26 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 27 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 28 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 29 --
## 
##   1  2  3  4  5
## 
## -- Imputation 30 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 31 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 32 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 33 --
## 
##   1  2  3  4  5  6  7  8  9 10
## 
## -- Imputation 34 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 35 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 36 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 37 --
## 
##   1  2  3  4  5  6  7  8  9 10 11
## 
## -- Imputation 38 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 39 --
## 
##   1  2  3  4  5  6  7  8  9 10
## 
## -- Imputation 40 --
## 
##   1  2  3  4  5  6  7  8  9 10
## 
## -- Imputation 41 --
## 
##   1  2  3  4  5  6  7  8  9 10
## 
## -- Imputation 42 --
## 
##   1  2  3  4  5  6  7  8  9 10
## 
## -- Imputation 43 --
## 
##   1  2  3  4  5  6  7  8  9 10
## 
## -- Imputation 44 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 45 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 46 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 47 --
## 
##   1  2  3  4  5  6  7  8  9 10 11
## 
## -- Imputation 48 --
## 
##   1  2  3  4  5  6  7  8  9 10 11
## 
## -- Imputation 49 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 50 --
## 
##   1  2  3  4  5  6  7  8  9 10 11 12

Creating new dataset with missing data imputed. On the second line of code a repeated measure analysis is condicted on the data set which has the data imputed.

data(MI$imputations)
## Warning in data(MI$imputations): data set 'MI$imputations' not found
allimplogreg<-lapply(MI$imputations,function(X) {lme(meanPERMA ~ GROUP * WAVE + BASELINE, random = ~1 | ID, data = X, method = "ML", na.action = "na.omit")})
betas<-MIextract(allimplogreg, fun=fixef)
vars<-MIextract(allimplogreg, fun=vcov)
summary<-summary(MIcombine(betas,vars))
## Multiple imputation results:
##       MIcombine.default(betas, vars)
##                results         se     (lower    upper) missInfo
## (Intercept)  3.8318434 0.67911594  2.4965658 5.1671209     36 %
## GROUP1       0.2082338 0.60755642 -0.9845257 1.4009933     26 %
## WAVE        -0.1771330 0.28000018 -0.7272405 0.3729745     31 %
## BASELINE     0.5091647 0.07818753  0.3550547 0.6632746     48 %
## GROUP1:WAVE  0.2025901 0.39407896 -0.5718395 0.9770196     33 %
summary
##                results         se     (lower    upper) missInfo
## (Intercept)  3.8318434 0.67911594  2.4965658 5.1671209     36 %
## GROUP1       0.2082338 0.60755642 -0.9845257 1.4009933     26 %
## WAVE        -0.1771330 0.28000018 -0.7272405 0.3729745     31 %
## BASELINE     0.5091647 0.07818753  0.3550547 0.6632746     48 %
## GROUP1:WAVE  0.2025901 0.39407896 -0.5718395 0.9770196     33 %
library(pander)

Table

  results se (lower upper) missInfo
(Intercept) 3.832 0.6791 2.497 5.167 36 %
GROUP1 0.2082 0.6076 -0.9845 1.401 26 %
WAVE -0.1771 0.28 -0.7272 0.373 31 %
BASELINE 0.5092 0.07819 0.3551 0.6633 48 %
GROUP1:WAVE 0.2026 0.3941 -0.5718 0.977 33 %

Check results with Imputations using Zelig

library("Zelig")
## Loading required package: boot
## 
## Attaching package: 'boot'
## 
## The following object is masked from 'package:car':
## 
##     logit
## 
## The following object is masked from 'package:psych':
## 
##     logit
## 
## Loading required package: MASS
## Loading required package: sandwich
## ZELIG (Versions 4.2-1, built: 2013-09-12)
## 
## +----------------------------------------------------------------+
## |  Please refer to http://gking.harvard.edu/zelig for full       |
## |  documentation or help.zelig() for help with commands and      |
## |  models support by Zelig.                                      |
## |                                                                |
## |  Zelig project citations:                                      |
## |    Kosuke Imai, Gary King, and Olivia Lau.  (2009).            |
## |    ``Zelig: Everyone's Statistical Software,''                 |
## |    http://gking.harvard.edu/zelig                              |
## |   and                                                          |
## |    Kosuke Imai, Gary King, and Olivia Lau. (2008).             |
## |    ``Toward A Common Framework for Statistical Analysis        |
## |    and Development,'' Journal of Computational and             |
## |    Graphical Statistics, Vol. 17, No. 4 (December)             |
## |    pp. 892-913.                                                |
## |                                                                |
## |   To cite individual Zelig models, please use the citation     |
## |   format printed with each model run and in the documentation. |
## +----------------------------------------------------------------+
## 
## 
## 
## Attaching package: 'Zelig'
## 
## The following objects are masked from 'package:psych':
## 
##     alpha, describe, sim
## 
## The following object is masked from 'package:utils':
## 
##     cite
zelig.fit <- zelig(meanPERMA ~ GROUP * WAVE + BASELINE, random = ~1 | ID, data = MI$imputations,  model = "ls", digits = 4, cite = F)
summary(zelig.fit)
## 
##   Model: ls
##   Number of multiply imputed data sets: 50 
## 
## Combined results:
## 
## Call:
## lm(formula = formula, weights = weights, model = F, data = data)
## 
## Coefficients:
##                  Value Std. Error     t-stat      p-value
## (Intercept)  3.8195395 0.68531408  5.5734146 4.589636e-08
## GROUP1       0.2087128 0.65358443  0.3193357 7.495399e-01
## WAVE        -0.1771330 0.30486019 -0.5810302 5.614044e-01
## BASELINE     0.5109341 0.07539588  6.7766844 1.550968e-10
## GROUP1:WAVE  0.2026039 0.42829210  0.4730508 6.363387e-01
## 
## For combined results from datasets i to j, use summary(x, subset = i:j).
## For separate results, use print(summary(x), subset = i:j).
summary1<-summary(zelig.fit)

Table with p-values

  Value Std. Error t-stat p-value
(Intercept) 3.82 0.6853 5.573 4.59e-08
GROUP1 0.2087 0.6536 0.3193 0.7495
WAVE -0.1771 0.3049 -0.581 0.5614
BASELINE 0.5109 0.0754 6.777 1.551e-10
GROUP1:WAVE 0.2026 0.4283 0.4731 0.6363

Check assumptions with Random Computations. Zailig fit with just one of the imputed data sets.

data1=MI$imputations[[1]]
library("Zelig")
zelig.fitdata1 <- zelig(meanPERMA ~ GROUP * WAVE + BASELINE, random = ~1 | ID, data = data1,  model = "ls", cite = FALSE)
summary(zelig.fitdata1)
## 
## Call:
## lm(formula = formula, weights = weights, model = F, data = data)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -4.641 -0.395  0.054  0.717  2.416 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  3.92179    0.52271   7.503 3.14e-12 ***
## GROUP1       0.51407    0.54458   0.944    0.347    
## WAVE        -0.01824    0.24758  -0.074    0.941    
## BASELINE     0.48454    0.04982   9.727  < 2e-16 ***
## GROUP1:WAVE -0.11583    0.34438  -0.336    0.737    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.148 on 173 degrees of freedom
## Multiple R-squared:  0.3583, Adjusted R-squared:  0.3435 
## F-statistic: 24.15 on 4 and 173 DF,  p-value: 6.913e-16

Describe the meanPERMA variable by the GROUP variable

describeBy(data1[,3:4], group = data1$GROUP)
## group: 0
##           vars  n mean   sd median trimmed  mad  min   max range  skew
## BASELINE     1 86 6.95 1.64   7.33    7.08 1.48 2.33  9.33  7.00 -0.72
## meanPERMA    2 86 7.26 1.51   7.60    7.36 1.38 1.67 10.35  8.69 -0.82
##           kurtosis   se
## BASELINE     -0.19 0.18
## meanPERMA     1.07 0.16
## -------------------------------------------------------- 
## group: 1
##           vars  n mean   sd median trimmed  mad min  max range  skew
## BASELINE     1 92 6.69 1.82    7.0    6.88 1.98   2 9.67  7.67 -0.74
## meanPERMA    2 92 7.48 1.32    7.8    7.62 1.18   4 9.58  5.58 -0.89
##           kurtosis   se
## BASELINE      0.02 0.19
## meanPERMA     0.23 0.14

Create a plot that visualizes meanPERMA variable by the GROUP variable. Load the proper packedes.

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

Take a look at the residuals. Of a random selected dataset with imputed data.

residual <- lm(meanPERMA ~ BASELINE, data=data1)$residual

Plot the residuals to see that they are random

# A density plot
plot(density(residual))

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

Checking the different between intervention and control groups residuals within the selected imputed dataset. This allows us to control for individual unsystematic differences.

data2$residual <- NA
sel1 <- which(!is.na(data1$meanPERMA)) 
sel2 <- which(!is.na(data1$BASELINE))
data1$residual[intersect(sel1,sel2)] <- residual
qplot(GROUP, meanPERMA, data=data1, geom="boxplot")

Plot of the difference between intervention and control groups within the selected imputed dataset.

qplot(GROUP, residual, data=data1, geom="boxplot")

Two way repeated measures on dataset Randomly Selected Imputed Data ======================================================== Graphing the Two-Way Interaction. Both meanPERMA and the Residuals

# nlme package
with(data1, boxplot(meanPERMA ~ WAVE + GROUP))

with(data1, boxplot(residual ~ WAVE + GROUP))
Linear Mixed-Effects Model

Comparing Basline to Wave 2 and 3 by Group.

fullModeldata1 <- lme(meanPERMA ~ GROUP * WAVE + BASELINE, random = ~1 | ID, data = data1, method = "ML", na.action = "na.omit")

Cooks Distence

CookD(fullModeldata1)

Plot Cook’s distance:

plot(fullModeldata1, which="cook")
Check results on this random Imputation model
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(fullModeldata1)
## Linear mixed-effects model fit by maximum likelihood
##  Data: data1 
##        AIC      BIC    logLik
##   559.4526 581.7251 -272.7263
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept) Residual
## StdDev:   0.5099926 1.010322
## 
## Fixed effects: meanPERMA ~ GROUP * WAVE + BASELINE 
##                 Value Std.Error DF   t-value p-value
## (Intercept)  3.945511 0.5215166 87  7.565457  0.0000
## GROUP1       0.513415 0.4984268 87  1.030071  0.3058
## WAVE        -0.018235 0.2210179 86 -0.082505  0.9344
## BASELINE     0.481128 0.0545037 86  8.827442  0.0000
## GROUP1:WAVE -0.115987 0.3074381 86 -0.377271  0.7069
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.509                     
## WAVE        -0.636  0.665              
## BASELINE    -0.727  0.021  0.000       
## GROUP1:WAVE  0.451 -0.925 -0.719  0.008
## 
## Standardized Within-Group Residuals:
##         Min          Q1         Med          Q3         Max 
## -3.63064391 -0.32147120  0.04898617  0.54013500  2.23444194 
## 
## Number of Observations: 178
## Number of Groups: 89

Another random selected imputation

data10=MI$imputations[[10]]
library("Zelig")
zelig.fitdata10 <- zelig(meanPERMA ~ GROUP * WAVE + BASELINE, random = ~1 | ID, data = data10,  model = "ls", cite = FALSE)
summary(zelig.fitdata10)
## 
## Call:
## lm(formula = formula, weights = weights, model = F, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.3111 -0.6085  0.0678  0.7280  2.9840 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  3.66115    0.57282   6.391 1.47e-09 ***
## GROUP1       0.41842    0.59611   0.702    0.484    
## WAVE        -0.19619    0.27101  -0.724    0.470    
## BASELINE     0.54179    0.05467   9.911  < 2e-16 ***
## GROUP1:WAVE  0.07721    0.37700   0.205    0.838    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.257 on 173 degrees of freedom
## Multiple R-squared:  0.373,  Adjusted R-squared:  0.3585 
## F-statistic: 25.73 on 4 and 173 DF,  p-value: < 2.2e-16

Describe the meanPERMA variable by the GROUP variable

describeBy(data10[,3:4], group = data10$GROUP)
## group: 0
##           vars  n mean   sd median trimmed  mad  min   max range  skew
## BASELINE     1 86 6.95 1.64   7.33    7.08 1.48 2.33  9.33  7.00 -0.72
## meanPERMA    2 86 7.13 1.71   7.61    7.22 1.61 1.67 10.78  9.12 -0.51
##           kurtosis   se
## BASELINE     -0.19 0.18
## meanPERMA     0.00 0.18
## -------------------------------------------------------- 
## group: 1
##           vars  n mean   sd median trimmed  mad min   max range  skew
## BASELINE     1 92 6.64 1.82   6.67    6.81 1.48   2  9.67  7.67 -0.69
## meanPERMA    2 92 7.50 1.41   7.66    7.61 1.01   4 10.77  6.77 -0.58
##           kurtosis   se
## BASELINE     -0.02 0.19
## meanPERMA     0.01 0.15

Create a plot that visualizes meanPERMA variable by the GROUP variable

library(ggplot2)
library(influence.ME)

Take a look at the residuals

residual <- lm(meanPERMA ~ BASELINE, data=data10)$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.

data10$residual <- NA
sel1 <- which(!is.na(data10$meanPERMA)) 
sel2 <- which(!is.na(data10$BASELINE))
data10$residual[intersect(sel1,sel2)] <- residual
qplot(GROUP, meanPERMA, data=data10, geom="boxplot")

Plot of the difference between intervention and control groups.

qplot(GROUP, residual, data=data10, geom="boxplot")

Two way repeated measures ======================================================== Graphing the Two-Way Interaction. Both meanPERMA and the Residuals

# Load the nlme package
library(nlme)
with(data10, boxplot(meanPERMA ~ WAVE + GROUP))

with(data10, boxplot(residual ~ WAVE + GROUP))
Linear Mixed-Effects Model

Comparing Basline to Wave 2 and 3 by Group.

fullModeldata10 <- lme(meanPERMA ~ GROUP * WAVE + BASELINE, random = ~1 | ID, data = data10, method = "ML", na.action = "na.omit")

Cooks Distence

CookD(fullModeldata10)

Plot Cook’s distance:

plot(fullModeldata10, which="cook")
Check results on this random Imputation model
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(fullModeldata10)
## Linear mixed-effects model fit by maximum likelihood
##  Data: data10 
##        AIC      BIC    logLik
##   586.9817 609.2542 -286.4909
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept) Residual
## StdDev:    0.679146  1.03616
## 
## Fixed effects: meanPERMA ~ GROUP * WAVE + BASELINE 
##                 Value Std.Error DF   t-value p-value
## (Intercept)  3.704181 0.5709325 87  6.487949  0.0000
## GROUP1       0.417324 0.5196089 87  0.803150  0.4241
## WAVE        -0.196188 0.2266704 86 -0.865519  0.3892
## BASELINE     0.535605 0.0621029 86  8.624473  0.0000
## GROUP1:WAVE  0.076654 0.3153393 86  0.243085  0.8085
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.486                     
## WAVE        -0.596  0.654              
## BASELINE    -0.756  0.021  0.000       
## GROUP1:WAVE  0.415 -0.910 -0.719  0.018
## 
## Standardized Within-Group Residuals:
##         Min          Q1         Med          Q3         Max 
## -2.84247043 -0.46943985  0.04025806  0.46647242  2.72392722 
## 
## Number of Observations: 178
## Number of Groups: 89

Another random selected imputation

data15=MI$imputations[[15]]
library("Zelig")
zelig.fitdata15 <- zelig(meanPERMA ~ GROUP * WAVE + BASELINE, random = ~1 | ID, data = data15,  model = "ls", cite = FALSE)
summary(zelig.fitdata15)
## 
## Call:
## lm(formula = formula, weights = weights, model = F, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.4687 -0.5315  0.0986  0.7084  2.6671 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  3.91433    0.54552   7.175 2.03e-11 ***
## GROUP1       0.27292    0.56709   0.481    0.631    
## WAVE        -0.10409    0.25776  -0.404    0.687    
## BASELINE     0.48583    0.05215   9.316  < 2e-16 ***
## GROUP1:WAVE  0.15760    0.35854   0.440    0.661    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.195 on 173 degrees of freedom
## Multiple R-squared:  0.3458, Adjusted R-squared:  0.3306 
## F-statistic: 22.86 on 4 and 173 DF,  p-value: 3.563e-15

Describe the meanPERMA variable by the GROUP variable

describeBy(data15[,3:4], group = data15$GROUP)
## group: 0
##           vars  n mean   sd median trimmed  mad  min   max range  skew
## BASELINE     1 86 6.95 1.64   7.33    7.08 1.48 2.33  9.33  7.00 -0.72
## meanPERMA    2 86 7.14 1.55   7.66    7.24 1.50 1.67 10.00  8.33 -0.76
##           kurtosis   se
## BASELINE     -0.19 0.18
## meanPERMA     0.54 0.17
## -------------------------------------------------------- 
## group: 1
##           vars  n mean   sd median trimmed  mad min  max range  skew
## BASELINE     1 92 6.68 1.81   7.00    6.86 1.97   2 9.67  7.67 -0.75
## meanPERMA    2 92 7.51 1.36   7.67    7.60 1.01   4 9.99  5.99 -0.55
##           kurtosis   se
## BASELINE       0.1 0.19
## meanPERMA     -0.3 0.14

Create a plot that visualizes meanPERMA variable by the GROUP variable

library(ggplot2)
library(influence.ME)

Take a look at the residuals

residual <- lm(meanPERMA ~ BASELINE, data=data15)$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(data15$meanPERMA)) 
sel2 <- which(!is.na(data15$BASELINE))
data15$residual[intersect(sel1,sel2)] <- residual
qplot(GROUP, meanPERMA, data=data15, geom="boxplot")

Plot of the difference between intervention and control groups.

qplot(GROUP, residual, data=data15, geom="boxplot")

Two way repeated measures ======================================================== Graphing the Two-Way Interaction. Both meanPERMA and the Residuals

# Load the nlme package
library(nlme)
with(data15, boxplot(meanPERMA ~ WAVE + GROUP))

with(data15, boxplot(residual ~ WAVE + GROUP))
Linear Mixed-Effects Model

Comparing Basline to Wave 2 and 3 by Group.

fullModeldata15 <- lme(meanPERMA ~ GROUP * WAVE + BASELINE, random = ~1 | ID, data = data15, method = "ML", na.action = "na.omit")

Cooks Distence

CookD(fullModeldata15)

Plot Cook’s distance:

plot(fullModeldata15, which="cook")
Check results on this random Imputation model
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(fullModeldata15)
## Linear mixed-effects model fit by maximum likelihood
##  Data: data15 
##        AIC      BIC    logLik
##   573.5474 595.8199 -279.7737
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept) Residual
## StdDev:   0.5394172 1.047553
## 
## Fixed effects: meanPERMA ~ GROUP * WAVE + BASELINE 
##                 Value Std.Error DF   t-value p-value
## (Intercept)  3.916473 0.5450818 87  7.185110  0.0000
## GROUP1       0.272829 0.5174491 87  0.527257  0.5994
## WAVE        -0.104089 0.2291625 86 -0.454214  0.6508
## BASELINE     0.485525 0.0573204 86  8.470379  0.0000
## GROUP1:WAVE  0.157598 0.3187573 86  0.494414  0.6223
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.513                     
## WAVE        -0.631  0.664              
## BASELINE    -0.731  0.032  0.000       
## GROUP1:WAVE  0.454 -0.924 -0.719 -0.002
## 
## Standardized Within-Group Residuals:
##        Min         Q1        Med         Q3        Max 
## -3.4489116 -0.3991776  0.1234776  0.5032868  1.7606283 
## 
## Number of Observations: 178
## Number of Groups: 89

Another randomly selected imputation

data25=MI$imputations[[25]]

library("Zelig")
zelig.fitdata25 <- zelig(meanPERMA ~ GROUP * WAVE + BASELINE, random = ~1 | ID, data = data25,  model = "ls", cite = FALSE)
summary(zelig.fitdata25)
## 
## Call:
## lm(formula = formula, weights = weights, model = F, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.2382 -0.6097  0.1363  0.7875  2.7423 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  3.15469    0.56760   5.558 1.02e-07 ***
## GROUP1       0.83840    0.59076   1.419    0.158    
## WAVE        -0.05992    0.26855  -0.223    0.824    
## BASELINE     0.57401    0.05417  10.597  < 2e-16 ***
## GROUP1:WAVE -0.22640    0.37355  -0.606    0.545    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.245 on 173 degrees of freedom
## Multiple R-squared:  0.4032, Adjusted R-squared:  0.3894 
## F-statistic: 29.22 on 4 and 173 DF,  p-value: < 2.2e-16

Describe the meanPERMA variable by the GROUP variable

describeBy(data25[,3:4], group = data25$GROUP)
## group: 0
##           vars  n mean   sd median trimmed  mad  min   max range  skew
## BASELINE     1 86 6.95 1.64   7.33    7.08 1.48 2.33  9.33  7.00 -0.72
## meanPERMA    2 86 7.06 1.70   7.46    7.19 1.67 1.67 10.10  8.43 -0.80
##           kurtosis   se
## BASELINE     -0.19 0.18
## meanPERMA     0.52 0.18
## -------------------------------------------------------- 
## group: 1
##           vars  n mean   sd median trimmed  mad  min   max range  skew
## BASELINE     1 92 6.66 1.82   6.67    6.83 1.48 2.00  9.67  7.67 -0.69
## meanPERMA    2 92 7.38 1.48   7.50    7.50 1.34 2.91 10.56  7.65 -0.71
##           kurtosis   se
## BASELINE      0.00 0.19
## meanPERMA     0.25 0.15

Create a plot that visualizes meanPERMA variable by the GROUP variable

library(ggplot2)
library(influence.ME)

Take a look at the residuals

residual <- lm(meanPERMA ~ BASELINE, data=data25)$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.

data25$residual <- NA
sel1 <- which(!is.na(data25$meanPERMA)) 
sel2 <- which(!is.na(data25$BASELINE))
data25$residual[intersect(sel1,sel2)] <- residual
qplot(GROUP, meanPERMA, data=data25, geom="boxplot")

Plot of the difference between intervention and control groups.

qplot(GROUP, residual, data=data25, geom="boxplot")

Two way repeated measures ======================================================== Graphing the Two-Way Interaction. Both meanPERMA and the Residuals

# Load the nlme package
library(nlme)
with(data25, boxplot(meanPERMA ~ WAVE + GROUP))

with(data25, boxplot(residual ~ WAVE + GROUP))
Linear Mixed-Effects Model

Comparing Basline to Wave 2 and 3 by Group.

fullModeldata25 <- lme(meanPERMA ~ GROUP * WAVE + BASELINE, random = ~1 | ID, data = data25, method = "ML", na.action = "na.omit")

Cooks Distence

CookD(fullModeldata25)

Plot Cook’s distance:

plot(fullModeldata25, which="cook")
Check results on this random Imputation model
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(fullModeldata25)
## Linear mixed-effects model fit by maximum likelihood
##  Data: data25 
##        AIC     BIC    logLik
##   588.7955 611.068 -287.3977
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept) Residual
## StdDev:   0.5382665 1.103313
## 
## Fixed effects: meanPERMA ~ GROUP * WAVE + BASELINE 
##                 Value Std.Error DF   t-value p-value
## (Intercept)  3.168326 0.5668236 87  5.589616  0.0000
## GROUP1       0.837949 0.5434870 87  1.541802  0.1268
## WAVE        -0.059918 0.2413607 86 -0.248251  0.8045
## BASELINE     0.572046 0.0590716 86  9.683938  0.0000
## GROUP1:WAVE -0.226481 0.3357341 86 -0.674583  0.5017
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.514                     
## WAVE        -0.639  0.666              
## BASELINE    -0.725  0.025  0.000       
## GROUP1:WAVE  0.454 -0.926 -0.719  0.008
## 
## Standardized Within-Group Residuals:
##         Min          Q1         Med          Q3         Max 
## -3.34571529 -0.48520708  0.08131318  0.53252997  2.05400263 
## 
## Number of Observations: 178
## Number of Groups: 89

Check assumptions on model without any imputations

Describe the meanPERMA 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 6.95 1.64   7.33    7.08 1.48 2.33  9.33  7.00 -0.72
## meanPERMA    2 59 7.23 1.62   8.00    7.38 0.99 1.67 10.00  8.33 -1.03
##           kurtosis   se
## BASELINE     -0.19 0.18
## meanPERMA     0.96 0.21
## -------------------------------------------------------- 
## group: 1
##           vars  n mean   sd median trimmed  mad min  max range  skew
## BASELINE     1 88 6.66 1.84   6.83    6.82 1.73   2 9.67  7.67 -0.72
## meanPERMA    2 54 7.65 1.26   8.00    7.82 0.99   4 9.33  5.33 -1.13
##           kurtosis   se
## BASELINE     -0.02 0.20
## meanPERMA     1.04 0.17

Create a plot that visualizes meanPERMA variable by the GROUP variable

library(ggplot2)
library(influence.ME)

Take a look at the residuals

residual <- lm(meanPERMA ~ 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.

data$residual <- NA
sel1 <- which(!is.na(data2$meanPERMA)) 
sel2 <- which(!is.na(data2$BASELINE))
data2$residual[intersect(sel1,sel2)] <- residual
qplot(GROUP, meanPERMA, 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).

Two way repeated measures ======================================================== Graphing the Two-Way Interaction. Both meanPERMA and the Residuals

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

with(data2, boxplot(residual ~ WAVE + GROUP))
Linear Mixed-Effects Model

Comparing Basline to Wave 2 and 3 by Group.

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

Cooks Distence

CookD(fullModel)

Plot Cook’s distance:

plot(fullModel, which="cook")
Results on Model with data that contains no imputations
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
##   355.1073 373.9467 -170.5537
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept)  Residual
## StdDev:   0.9208076 0.8265419
## 
## Fixed effects: meanPERMA ~ GROUP * WAVE + BASELINE 
##                 Value Std.Error DF   t-value p-value
## (Intercept)  3.653417 0.7037175 66  5.191597  0.0000
## GROUP1       0.165802 0.5680452 66  0.291882  0.7713
## WAVE        -0.245588 0.2439710 38 -1.006630  0.3205
## BASELINE     0.531144 0.0862032 66  6.161538  0.0000
## GROUP1:WAVE  0.379713 0.3563096 38  1.065682  0.2933
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.351                     
## WAVE        -0.415  0.589              
## BASELINE    -0.837 -0.024 -0.071       
## GROUP1:WAVE  0.275 -0.866 -0.686  0.060
## 
## Standardized Within-Group Residuals:
##         Min          Q1         Med          Q3         Max 
## -2.78596293 -0.30057260  0.08959737  0.43971370  2.29449221 
## 
## Number of Observations: 109
## Number of Groups: 69

Table with confidence intervals

Table with confidence intervals

  lower est. upper
(Intercept) 2.281 3.653 5.026
GROUP1 -0.942 0.1658 1.274
WAVE -0.728 -0.2456 0.2368
BASELINE 0.363 0.5311 0.6993
GROUP1:WAVE -0.3249 0.3797 1.084

Table with p-values

  Value Std.Error DF t-value p-value
(Intercept) 3.653 0.7037 66 5.192 2.174e-06
GROUP1 0.1658 0.568 66 0.2919 0.7713
WAVE -0.2456 0.244 38 -1.007 0.3205
BASELINE 0.5311 0.0862 66 6.162 4.859e-08
GROUP1:WAVE 0.3797 0.3563 38 1.066 0.2933