title: “Nagative Emotion Perma (PERMA) with Imputed Data Intention to treat model (ITT)”

Loading the dataset

setwd("~/Dropbox/ADULT STUDY")
data.test4 <- read.csv("adult_study011615.csv")
# Load the psych package
library(psych)
items <- c("PERMA5" ,"PERMA10", "PERMA14")
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
## 
## -- Imputation 2 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 3 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 4 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 5 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 6 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 7 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 8 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 9 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 10 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 11 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 12 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 13 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 14 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 15 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 16 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 17 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 18 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 19 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 20 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 21 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 22 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 23 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 24 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 25 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 26 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 27 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 28 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 29 --
## 
##   1  2  3  4  5  6  7
## 
## -- 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
## 
## -- Imputation 33 --
## 
##   1  2  3  4  5
## 
## -- Imputation 34 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 35 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 36 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 37 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 38 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 39 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 40 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 41 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 42 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 43 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 44 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 45 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 46 --
## 
##   1  2  3  4  5
## 
## -- Imputation 47 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 48 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 49 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 50 --
## 
##   1  2  3  4  5  6  7

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)  1.43488939 0.5516914  0.3513278 2.5184510     29 %
## GROUP1      -0.42525930 0.6390369 -1.6796981 0.8291795     25 %
## WAVE        -0.29864473 0.2933458 -0.8748901 0.2776006     30 %
## BASELINE     0.62447850 0.0737461  0.4793384 0.7696185     41 %
## GROUP1:WAVE -0.04406072 0.4089681 -0.8474706 0.7593491     31 %
summary
##                 results        se     (lower    upper) missInfo
## (Intercept)  1.43488939 0.5516914  0.3513278 2.5184510     29 %
## GROUP1      -0.42525930 0.6390369 -1.6796981 0.8291795     25 %
## WAVE        -0.29864473 0.2933458 -0.8748901 0.2776006     30 %
## BASELINE     0.62447850 0.0737461  0.4793384 0.7696185     41 %
## GROUP1:WAVE -0.04406072 0.4089681 -0.8474706 0.7593491     31 %
library(pander)

Table

  results se (lower upper) missInfo
(Intercept) 1.435 0.5517 0.3513 2.518 29 %
GROUP1 -0.4253 0.639 -1.68 0.8292 25 %
WAVE -0.2986 0.2933 -0.8749 0.2776 30 %
BASELINE 0.6245 0.07375 0.4793 0.7696 41 %
GROUP1:WAVE -0.04406 0.409 -0.8475 0.7593 31 %

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)  1.42850440 0.57596488  2.48019358 1.336650e-02
## GROUP1      -0.42477270 0.69146888 -0.61430487 5.391450e-01
## WAVE        -0.29864473 0.32177195 -0.92812545 3.536304e-01
## BASELINE     0.62598153 0.07026347  8.90906065 1.043830e-16
## GROUP1:WAVE -0.04394814 0.44844855 -0.09800041 9.219578e-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) 1.429 0.576 2.48 0.01337
GROUP1 -0.4248 0.6915 -0.6143 0.5391
WAVE -0.2986 0.3218 -0.9281 0.3536
BASELINE 0.626 0.07026 8.909 1.044e-16
GROUP1:WAVE -0.04395 0.4484 -0.098 0.922

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 
## -3.12618 -0.91475  0.00031  0.83159  3.14196 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.65383    0.49404   3.348    0.001 ** 
## GROUP1      -0.64815    0.61325  -1.057    0.292    
## WAVE        -0.41946    0.27858  -1.506    0.134    
## BASELINE     0.61450    0.05267  11.667   <2e-16 ***
## GROUP1:WAVE  0.16837    0.38750   0.435    0.664    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.292 on 173 degrees of freedom
## Multiple R-squared:  0.4654, Adjusted R-squared:  0.453 
## F-statistic: 37.65 on 4 and 173 DF,  p-value: < 2.2e-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 4.25 1.83   4.00    4.08 1.48 1.00 9.33  8.33 0.78
## meanPERMA    2 86 3.64 1.81   3.62    3.50 1.91 0.33 8.67  8.33 0.63
##           kurtosis  se
## BASELINE      0.48 0.2
## meanPERMA     0.06 0.2
## -------------------------------------------------------- 
## group: 1
##           vars  n mean   sd median trimmed  mad  min  max range skew
## BASELINE     1 92 3.82 1.86   4.00    3.74 2.47 0.67 7.67  7.00 0.26
## meanPERMA    2 92 2.98 1.63   2.67    2.90 1.98 0.33 7.00  6.67 0.33
##           kurtosis   se
## BASELINE     -1.01 0.19
## meanPERMA    -0.93 0.17

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
##   601.0582 623.3307 -293.5291
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept) Residual
## StdDev:   0.5878978 1.129615
## 
## Fixed effects: meanPERMA ~ GROUP * WAVE + BASELINE 
##                  Value Std.Error DF   t-value p-value
## (Intercept)  1.6533271 0.4706156 87  3.513116  0.0007
## GROUP1      -0.6480883 0.5587622 87 -1.159864  0.2493
## WAVE        -0.4194638 0.2471145 86 -1.697447  0.0932
## BASELINE     0.6146145 0.0579226 86 10.610959  0.0000
## GROUP1:WAVE  0.1683641 0.3437393 86  0.489802  0.6255
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.639                     
## WAVE        -0.788  0.663              
## BASELINE    -0.523  0.052  0.000       
## GROUP1:WAVE  0.571 -0.923 -0.719 -0.008
## 
## Standardized Within-Group Residuals:
##         Min          Q1         Med          Q3         Max 
## -2.43070353 -0.59601666 -0.05508928  0.58725037  2.44588308 
## 
## 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 
## -3.02650 -0.91718 -0.07639  0.84725  3.05441 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.93898    0.50880   3.811 0.000192 ***
## GROUP1      -0.41652    0.63093  -0.660 0.510024    
## WAVE        -0.29626    0.28677  -1.033 0.303016    
## BASELINE     0.50251    0.05434   9.248  < 2e-16 ***
## GROUP1:WAVE -0.12814    0.39892  -0.321 0.748425    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.33 on 173 degrees of freedom
## Multiple R-squared:  0.3812, Adjusted R-squared:  0.3669 
## F-statistic: 26.64 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 4.25 1.83   4.00    4.08 1.48 1.00 9.33  8.33 0.78
## meanPERMA    2 86 3.63 1.70   3.67    3.54 1.70 0.33 8.67  8.33 0.49
##           kurtosis   se
## BASELINE      0.48 0.20
## meanPERMA     0.02 0.18
## -------------------------------------------------------- 
## group: 1
##           vars  n mean   sd median trimmed  mad  min  max range skew
## BASELINE     1 92 3.82 1.86   3.96    3.73 2.42 0.67 7.67  7.00 0.26
## meanPERMA    2 92 2.80 1.55   2.67    2.72 1.83 0.33 7.00  6.67 0.37
##           kurtosis   se
## BASELINE     -0.98 0.19
## meanPERMA    -0.67 0.16

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
##   611.5973 633.8698 -298.7986
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept) Residual
## StdDev:   0.5973666 1.166897
## 
## Fixed effects: meanPERMA ~ GROUP * WAVE + BASELINE 
##                  Value Std.Error DF   t-value p-value
## (Intercept)  1.9476982 0.4853849 87  4.012688  0.0001
## GROUP1      -0.4171580 0.5762411 87 -0.723930  0.4711
## WAVE        -0.2962564 0.2552703 86 -1.160560  0.2490
## BASELINE     0.5004538 0.0596233 86  8.393590  0.0000
## GROUP1:WAVE -0.1283102 0.3551049 86 -0.361330  0.7187
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.630                     
## WAVE        -0.789  0.664              
## BASELINE    -0.522  0.032  0.000       
## GROUP1:WAVE  0.560 -0.924 -0.719  0.014
## 
## Standardized Within-Group Residuals:
##         Min          Q1         Med          Q3         Max 
## -2.17009570 -0.61790601 -0.04012348  0.67483655  2.23886087 
## 
## 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 
## -3.2486 -0.7760 -0.0850  0.8058  4.5734 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.88700    0.49467   1.793   0.0747 .  
## GROUP1       0.25548    0.61419   0.416   0.6780    
## WAVE        -0.14848    0.27901  -0.532   0.5953    
## BASELINE     0.68597    0.05268  13.021   <2e-16 ***
## GROUP1:WAVE -0.21230    0.38809  -0.547   0.5851    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.294 on 173 degrees of freedom
## Multiple R-squared:  0.5032, Adjusted R-squared:  0.4917 
## F-statistic:  43.8 on 4 and 173 DF,  p-value: < 2.2e-16

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 4.25 1.83   4.00    4.08 1.48 1.00 9.33  8.33 0.78
## meanPERMA    2 86 3.58 1.78   3.33    3.45 1.98 0.33 8.67  8.33 0.66
##           kurtosis   se
## BASELINE      0.48 0.20
## meanPERMA    -0.08 0.19
## -------------------------------------------------------- 
## group: 1
##           vars  n mean   sd median trimmed  mad  min  max range skew
## BASELINE     1 92 3.79 1.87   3.83     3.7 2.22 0.67 7.67  7.00 0.28
## meanPERMA    2 92 3.20 1.83   3.02     3.1 1.93 0.33 9.01  8.68 0.49
##           kurtosis   se
## BASELINE     -0.99 0.19
## meanPERMA    -0.25 0.19

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
##   593.1205 615.393 -289.5603
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept) Residual
## StdDev:   0.7691035 1.017416
## 
## Fixed effects: meanPERMA ~ GROUP * WAVE + BASELINE 
##                  Value Std.Error DF   t-value p-value
## (Intercept)  0.8824480 0.4539484 87  1.943939  0.0551
## GROUP1       0.2560179 0.5176291 87  0.494597  0.6221
## WAVE        -0.1484771 0.2225699 86 -0.667103  0.5065
## BASELINE     0.6870457 0.0614176 86 11.186454  0.0000
## GROUP1:WAVE -0.2123309 0.3095916 86 -0.685842  0.4947
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.621                     
## WAVE        -0.735  0.645              
## BASELINE    -0.575  0.059  0.000       
## GROUP1:WAVE  0.532 -0.897 -0.719 -0.006
## 
## Standardized Within-Group Residuals:
##         Min          Q1         Med          Q3         Max 
## -2.41509088 -0.52256274 -0.06249041  0.51136376  3.06859099 
## 
## 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 
## -3.1821 -0.8564 -0.1077  0.8439  2.8669 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   1.2017     0.4981   2.412   0.0169 *  
## GROUP1       -0.6267     0.6180  -1.014   0.3120    
## WAVE         -0.3341     0.2809  -1.189   0.2360    
## BASELINE      0.6812     0.0531  12.830   <2e-16 ***
## GROUP1:WAVE   0.2434     0.3908   0.623   0.5342    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.303 on 173 degrees of freedom
## Multiple R-squared:  0.502,  Adjusted R-squared:  0.4905 
## F-statistic:  43.6 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 4.25 1.83   4.00    4.08 1.48 1.00 9.33  8.33 0.78
## meanPERMA    2 86 3.59 1.89   3.33    3.43 1.98 0.33 9.93  9.60 0.85
##           kurtosis  se
## BASELINE      0.48 0.2
## meanPERMA     0.73 0.2
## -------------------------------------------------------- 
## group: 1
##           vars  n mean   sd median trimmed  mad   min  max range skew
## BASELINE     1 92 3.82 1.86   4.00    3.73 2.47  0.67 7.67  7.00 0.25
## meanPERMA    2 92 3.04 1.73   2.97    2.97 1.84 -0.25 7.00  7.25 0.24
##           kurtosis   se
## BASELINE     -0.99 0.19
## meanPERMA    -0.83 0.18

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
##   605.4264 627.6989 -295.7132
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept) Residual
## StdDev:   0.5354682 1.167113
## 
## Fixed effects: meanPERMA ~ GROUP * WAVE + BASELINE 
##                  Value Std.Error DF   t-value p-value
## (Intercept)  1.2096244 0.4789531 87  2.525559  0.0134
## GROUP1      -0.6272231 0.5734816 87 -1.093711  0.2771
## WAVE        -0.3340770 0.2553175 86 -1.308476  0.1942
## BASELINE     0.6793669 0.0574533 86 11.824691  0.0000
## GROUP1:WAVE  0.2432386 0.3551720 86  0.684847  0.4953
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.634                     
## WAVE        -0.800  0.668              
## BASELINE    -0.510  0.030  0.000       
## GROUP1:WAVE  0.568 -0.928 -0.719  0.014
## 
## Standardized Within-Group Residuals:
##        Min         Q1        Med         Q3        Max 
## -2.4241472 -0.6189406 -0.1010993  0.6410359  2.0922056 
## 
## 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 4.25 1.83   4.00    4.08 1.48 1.00 9.33  8.33 0.78
## meanPERMA    2 59 3.51 1.83   3.33    3.37 1.98 0.33 8.67  8.33 0.67
##           kurtosis   se
## BASELINE      0.48 0.20
## meanPERMA     0.08 0.24
## -------------------------------------------------------- 
## group: 1
##           vars  n mean   sd median trimmed  mad  min  max range skew
## BASELINE     1 88 3.86 1.88   4.00    3.78 2.47 0.67 7.67  7.00 0.22
## meanPERMA    2 54 2.88 1.63   2.67    2.79 1.98 0.33 7.00  6.67 0.39
##           kurtosis   se
## BASELINE     -1.02 0.20
## meanPERMA    -0.68 0.22

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
##   366.9236 385.763 -176.4618
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept)  Residual
## StdDev:   0.9594991 0.8803871
## 
## Fixed effects: meanPERMA ~ GROUP * WAVE + BASELINE 
##                  Value Std.Error DF   t-value p-value
## (Intercept)  1.4616070 0.5160475 66  2.832311  0.0061
## GROUP1      -0.4435431 0.6022424 66 -0.736486  0.4640
## WAVE        -0.3037856 0.2589326 38 -1.173223  0.2480
## BASELINE     0.6239830 0.0804480 66  7.756357  0.0000
## GROUP1:WAVE -0.0404192 0.3783578 38 -0.106828  0.9155
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.540                     
## WAVE        -0.669  0.591              
## BASELINE    -0.611  0.005 -0.034       
## GROUP1:WAVE  0.459 -0.869 -0.684  0.021
## 
## Standardized Within-Group Residuals:
##         Min          Q1         Med          Q3         Max 
## -2.63332946 -0.47859489 -0.01260174  0.45510572  1.87656441 
## 
## Number of Observations: 109
## Number of Groups: 69

Table with confidence intervals

Table with confidence intervals

  lower est. upper
(Intercept) 0.4552 1.462 2.468
GROUP1 -1.618 -0.4435 0.731
WAVE -0.8158 -0.3038 0.2082
BASELINE 0.4671 0.624 0.7809
GROUP1:WAVE -0.7886 -0.04042 0.7078

Table with p-values

  Value Std.Error DF t-value p-value
(Intercept) 1.462 0.516 66 2.832 0.006122
GROUP1 -0.4435 0.6022 66 -0.7365 0.464
WAVE -0.3038 0.2589 38 -1.173 0.248
BASELINE 0.624 0.08045 66 7.756 7.228e-11
GROUP1:WAVE -0.04042 0.3784 38 -0.1068 0.9155