Loading the dataset

data.test4 <- read.csv("/Volumes/TOSHIBA EXT/Dropbox/ADULT STUDY/adult_study011615.csv")
# Load the psych package
library(psych)
items <- c("MLQ1" ,"MLQ4", "MLQ5", "MLQ6", "MLQ9")
scaleKey <- c(1, 1, 1,1,-1)
data.test4$meanmlq  <- 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 meanmlq and ID Group and wave from dtat.test4 and create a new #dataset with only those variables.
data <- data.test4[,c("ID", "GROUP", "wave", "meanmlq")]
#Use dcast to cnage from long-format data to wide format data
data <- dcast(data, ID + GROUP ~ wave, mean, value.var = "meanmlq")
# 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 meanmlq and wave 2 and 3 of meanmlq. 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", "meanmlq", "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
## 
## -- Imputation 2 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 3 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 4 --
## 
##   1  2  3  4  5  6  7  8  9 10 11
## 
## -- Imputation 5 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 6 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 7 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 8 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 9 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 10 --
## 
##   1  2  3  4  5  6  7  8  9 10
## 
## -- Imputation 11 --
## 
##   1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
## 
## -- Imputation 12 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 13 --
## 
##   1  2  3  4  5
## 
## -- Imputation 14 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 15 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 16 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 17 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 18 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 19 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 20 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 21 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 22 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 23 --
## 
##   1  2  3  4  5  6  7  8  9 10
## 
## -- Imputation 24 --
## 
##   1  2  3  4  5
## 
## -- Imputation 25 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 26 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 27 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 28 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 29 --
## 
##   1  2  3  4  5  6  7  8  9 10 11
## 
## -- Imputation 30 --
## 
##   1  2  3  4  5  6  7  8  9 10 11
## 
## -- Imputation 31 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 32 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 33 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 34 --
## 
##   1  2  3  4  5  6  7  8  9 10 11
## 
## -- Imputation 35 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 36 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 37 --
## 
##   1  2  3  4  5  6  7  8  9 10
## 
## -- Imputation 38 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 39 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 40 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 41 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 42 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 43 --
## 
##   1  2  3  4  5  6  7  8  9 10 11
## 
## -- Imputation 44 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 45 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 46 --
## 
##   1  2  3  4  5  6  7  8  9 10 11 12
## 
## -- Imputation 47 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 48 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 49 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 50 --
## 
##   1  2  3  4  5  6  7  8

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(meanmlq ~ 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(MIcombine(betas,vars))
## Multiple imputation results:
##       MIcombine.default(betas, vars)
##               results         se      (lower    upper) missInfo
## (Intercept) 1.7767539 0.36093107  1.06776783 2.4857401     30 %
## GROUP1      0.7336857 0.35921667  0.02857907 1.4387924     25 %
## WAVE        0.1089754 0.16793232 -0.22099466 0.4389454     32 %
## BASELINE    0.6446072 0.05695019  0.53244822 0.7567662     45 %
## GROUP1:WAVE 0.0146294 0.22692512 -0.43098786 0.4602467     28 %

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(meanmlq ~ GROUP * WAVE + BASELINE, random = ~1 | ID, data = MI$imputations,  model = "ls", cite = FALSE)
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.77206540 0.36760741  4.82053772 1.819238e-06
## GROUP1      0.73387356 0.38673665  1.89760541 5.801343e-02
## WAVE        0.10897537 0.18256404  0.59691582 5.507643e-01
## BASELINE    0.64559355 0.05462097 11.81951895 2.888713e-25
## GROUP1:WAVE 0.01463473 0.24783595  0.05905006 9.529253e-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).

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

data1=MI$imputations[[1]]
library("Zelig")
zelig.fitdata1 <- zelig(meanmlq ~ 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 
## -2.58008 -0.39312  0.06283  0.38723  1.95265 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.74379    0.30451   5.727 4.45e-08 ***
## GROUP1       0.78088    0.33635   2.322   0.0214 *  
## WAVE         0.18459    0.15289   1.207   0.2290    
## BASELINE     0.65162    0.03895  16.728  < 2e-16 ***
## GROUP1:WAVE -0.09546    0.21267  -0.449   0.6541    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.7089 on 173 degrees of freedom
## Multiple R-squared:  0.6378, Adjusted R-squared:  0.6295 
## F-statistic: 76.17 on 4 and 173 DF,  p-value: < 2.2e-16

Describe the meanmlq 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.75 1.27    4.8    4.82 1.19 1.4 7.0   5.6 -0.43
## meanmlq     2 86 5.12 1.20    5.2    5.15 1.24 2.4 7.3   4.9 -0.28
##          kurtosis   se
## BASELINE    -0.20 0.14
## meanmlq     -0.61 0.13
## -------------------------------------------------------- 
## group: 1
##          vars  n mean   sd median trimmed  mad min  max range  skew
## BASELINE    1 92 4.56 1.46    4.5    4.57 1.63 1.8 7.00  5.20 -0.02
## meanmlq     2 92 5.63 1.08    5.8    5.67 1.23 2.6 7.96  5.35 -0.28
##          kurtosis   se
## BASELINE    -1.07 0.15
## meanmlq     -0.57 0.11

Create a plot that visualizes meanmlq 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(meanmlq ~ 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$meanmlq)) 
sel2 <- which(!is.na(data1$BASELINE))
data1$residual[intersect(sel1,sel2)] <- residual
qplot(GROUP, meanmlq, 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 meanmlq and the Residuals

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

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

Comparing Basline to Wave 2 and 3 by Group.

fullModeldata1 <- lme(meanmlq ~ 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
##   389.2008 411.4732 -187.6004
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept)  Residual
## StdDev:   0.2824298 0.6392931
## 
## Fixed effects: meanmlq ~ GROUP * WAVE + BASELINE 
##                  Value  Std.Error DF   t-value p-value
## (Intercept)  1.7454545 0.30110209 87  5.796886  0.0000
## GROUP1       0.7808047 0.31364260 87  2.489473  0.0147
## WAVE         0.1845854 0.13985171 86  1.319865  0.1904
## BASELINE     0.6512675 0.04199939 86 15.506594  0.0000
## GROUP1:WAVE -0.0954610 0.19452899 86 -0.490729  0.6249
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.556                     
## WAVE        -0.697  0.669              
## BASELINE    -0.663  0.028  0.000       
## GROUP1:WAVE  0.502 -0.930 -0.719 -0.001
## 
## Standardized Within-Group Residuals:
##        Min         Q1        Med         Q3        Max 
## -3.4851504 -0.6329056  0.0580462  0.5870427  2.5915227 
## 
## Number of Observations: 178
## Number of Groups: 89

Another random selected imputation

data10=MI$imputations[[10]]
library("Zelig")
zelig.fitdata10 <- zelig(meanmlq ~ 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 
## -2.38067 -0.46064  0.00618  0.44047  2.01787 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.54530    0.30398   5.084 9.55e-07 ***
## GROUP1       0.91918    0.33512   2.743  0.00673 ** 
## WAVE         0.06271    0.15229   0.412  0.68103    
## BASELINE     0.70681    0.03903  18.110  < 2e-16 ***
## GROUP1:WAVE -0.10003    0.21184  -0.472  0.63737    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.7061 on 173 degrees of freedom
## Multiple R-squared:  0.6765, Adjusted R-squared:  0.669 
## F-statistic: 90.43 on 4 and 173 DF,  p-value: < 2.2e-16

Describe the meanmlq 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.75 1.27    4.8    4.82 1.19 1.40 7.00  5.60 -0.43
## meanmlq     2 86 5.00 1.22    5.2    5.05 1.19 1.39 7.53  6.14 -0.54
##          kurtosis   se
## BASELINE    -0.20 0.14
## meanmlq      0.36 0.13
## -------------------------------------------------------- 
## group: 1
##          vars  n mean   sd median trimmed  mad  min  max range  skew
## BASELINE    1 92 4.53 1.45   4.47    4.54 1.58 1.80 7.00  5.20  0.00
## meanmlq     2 92 5.61 1.17   5.80    5.64 1.19 2.88 8.61  5.73 -0.17
##          kurtosis   se
## BASELINE    -1.02 0.15
## meanmlq     -0.63 0.12

Create a plot that visualizes meanmlq variable by the GROUP variable

library(ggplot2)
library(influence.ME)

Take a look at the residuals

residual <- lm(meanmlq ~ 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$meanmlq)) 
sel2 <- which(!is.na(data10$BASELINE))
data10$residual[intersect(sel1,sel2)] <- residual
qplot(GROUP, meanmlq, 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 meanmlq and the Residuals

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

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

Comparing Basline to Wave 2 and 3 by Group.

fullModeldata10 <- lme(meanmlq ~ 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
##   385.196 407.4685 -185.598
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept)  Residual
## StdDev:    0.336788 0.6092767
## 
## Fixed effects: meanmlq ~ GROUP * WAVE + BASELINE 
##                  Value  Std.Error DF   t-value p-value
## (Intercept)  1.5524311 0.29921831 87  5.188289  0.0000
## GROUP1       0.9187533 0.30220709 87  3.040145  0.0031
## WAVE         0.0627062 0.13328530 86  0.470466  0.6392
## BASELINE     0.7053085 0.04332082 86 16.281050  0.0000
## GROUP1:WAVE -0.0999698 0.18540400 86 -0.539200  0.5911
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.549                     
## WAVE        -0.668  0.662              
## BASELINE    -0.688  0.040  0.000       
## GROUP1:WAVE  0.487 -0.921 -0.719 -0.010
## 
## Standardized Within-Group Residuals:
##         Min          Q1         Med          Q3         Max 
## -3.34787770 -0.56733010  0.03271444  0.51477358  2.71590672 
## 
## Number of Observations: 178
## Number of Groups: 89

Another random selected imputation

data15=MI$imputations[[15]]
library("Zelig")
zelig.fitdata15 <- zelig(meanmlq ~ 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 
## -2.56858 -0.45680 -0.00462  0.43122  1.93020 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.68621    0.30714   5.490 1.41e-07 ***
## GROUP1       0.77416    0.33966   2.279   0.0239 *  
## WAVE         0.24254    0.15442   1.571   0.1181    
## BASELINE     0.63575    0.03920  16.218  < 2e-16 ***
## GROUP1:WAVE -0.03176    0.21481  -0.148   0.8826    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.716 on 173 degrees of freedom
## Multiple R-squared:  0.6319, Adjusted R-squared:  0.6234 
## F-statistic: 74.25 on 4 and 173 DF,  p-value: < 2.2e-16

Describe the meanmlq 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.75 1.27    4.8    4.82 1.19 1.40 7.00  5.60 -0.43
## meanmlq     2 86 5.07 1.18    5.2    5.13 1.01 2.01 7.14  5.13 -0.52
##          kurtosis   se
## BASELINE    -0.20 0.14
## meanmlq     -0.12 0.13
## -------------------------------------------------------- 
## group: 1
##          vars  n mean   sd median trimmed  mad  min  max range  skew
## BASELINE    1 92 4.54 1.47    4.4    4.54 1.74 1.80 7.00  5.20  0.02
## meanmlq     2 92 5.66 1.09    5.8    5.70 1.18 3.22 8.37  5.15 -0.23
##          kurtosis   se
## BASELINE    -1.08 0.15
## meanmlq     -0.67 0.11

Create a plot that visualizes meanmlq variable by the GROUP variable

library(ggplot2)
library(influence.ME)

Take a look at the residuals

residual <- lm(meanmlq ~ 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$meanmlq)) 
sel2 <- which(!is.na(data15$BASELINE))
data15$residual[intersect(sel1,sel2)] <- residual
qplot(GROUP, meanmlq, 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 meanmlq and the Residuals

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

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

Comparing Basline to Wave 2 and 3 by Group.

fullModeldata15 <- lme(meanmlq ~ 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
##   395.1575 417.43 -190.5788
## 
## Random effects:
##  Formula: ~1 | ID
##          (Intercept)  Residual
## StdDev: 0.0001173795 0.7059073
## 
## Fixed effects: meanmlq ~ GROUP * WAVE + BASELINE 
##                  Value Std.Error DF   t-value p-value
## (Intercept)  1.6862109 0.3071424 87  5.489997  0.0000
## GROUP1       0.7741605 0.3396558 87  2.279250  0.0251
## WAVE         0.2425435 0.1544242 86  1.570631  0.1199
## BASELINE     0.6357460 0.0391989 86 16.218482  0.0000
## GROUP1:WAVE -0.0317599 0.2148145 86 -0.147848  0.8828
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.579                     
## WAVE        -0.754  0.682              
## BASELINE    -0.607  0.013  0.000       
## GROUP1:WAVE  0.535 -0.948 -0.719  0.012
## 
## Standardized Within-Group Residuals:
##          Min           Q1          Med           Q3          Max 
## -3.638693590 -0.647117517 -0.006538178  0.610875757  2.734358880 
## 
## Number of Observations: 178
## Number of Groups: 89

Another randomly selected imputation

data25=MI$imputations[[25]]

library("Zelig")
zelig.fitdata25 <- zelig(meanmlq ~ 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 
## -2.29332 -0.46248  0.01387  0.44724  2.31714 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.55202    0.29580   5.247 4.48e-07 ***
## GROUP1       0.29493    0.32731   0.901    0.369    
## WAVE        -0.04618    0.14878  -0.310    0.757    
## BASELINE     0.73492    0.03773  19.480  < 2e-16 ***
## GROUP1:WAVE  0.26527    0.20695   1.282    0.202    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.6899 on 173 degrees of freedom
## Multiple R-squared:  0.7039, Adjusted R-squared:  0.697 
## F-statistic: 102.8 on 4 and 173 DF,  p-value: < 2.2e-16

Describe the meanmlq 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.75 1.27    4.8    4.82 1.19 1.40   7  5.60 -0.43
## meanmlq     2 86 4.98 1.23    5.2    5.02 1.20 1.49   7  5.51 -0.42
##          kurtosis   se
## BASELINE    -0.20 0.14
## meanmlq     -0.41 0.13
## -------------------------------------------------------- 
## group: 1
##          vars  n mean   sd median trimmed  mad  min  max range  skew
## BASELINE    1 92 4.57 1.47   4.50    4.58 1.63 1.80 7.00  5.20 -0.02
## meanmlq     2 92 5.53 1.22   5.74    5.57 1.43 2.57 8.34  5.76 -0.17
##          kurtosis   se
## BASELINE    -1.09 0.15
## meanmlq     -0.76 0.13

Create a plot that visualizes meanmlq variable by the GROUP variable

library(ggplot2)
library(influence.ME)

Take a look at the residuals

residual <- lm(meanmlq ~ 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$meanmlq)) 
sel2 <- which(!is.na(data25$BASELINE))
data25$residual[intersect(sel1,sel2)] <- residual
qplot(GROUP, meanmlq, 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 meanmlq and the Residuals

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

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

Comparing Basline to Wave 2 and 3 by Group.

fullModeldata25 <- lme(meanmlq ~ 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
##   380.9999 403.2724 -183.5
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept)  Residual
## StdDev:    0.215478 0.6450675
## 
## Fixed effects: meanmlq ~ GROUP * WAVE + BASELINE 
##                  Value  Std.Error DF   t-value p-value
## (Intercept)  1.5547457 0.29371233 87  5.293430  0.0000
## GROUP1       0.2948024 0.31391510 87  0.939115  0.3503
## WAVE        -0.0461787 0.14111490 86 -0.327242  0.7443
## BASELINE     0.7343484 0.03956579 86 18.560185  0.0000
## GROUP1:WAVE  0.2652789 0.19628758 86  1.351481  0.1801
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.569                     
## WAVE        -0.721  0.674              
## BASELINE    -0.640  0.027  0.000       
## GROUP1:WAVE  0.521 -0.938 -0.719 -0.004
## 
## Standardized Within-Group Residuals:
##        Min         Q1        Med         Q3        Max 
## -3.3727940 -0.6730107  0.0708485  0.6217148  3.3782413 
## 
## Number of Observations: 178
## Number of Groups: 89

Check assumptions on model without any imputations

Describe the meanmlq 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.75 1.27    4.8    4.82 1.19 1.4   7   5.6 -0.43
## meanmlq     2 59 5.17 1.15    5.4    5.22 1.19 2.4   7   4.6 -0.45
##          kurtosis   se
## BASELINE    -0.20 0.14
## meanmlq     -0.38 0.15
## -------------------------------------------------------- 
## group: 1
##          vars  n mean   sd median trimmed  mad min max range  skew
## BASELINE    1 88 4.50 1.47    4.4    4.50 1.63 1.8   7   5.2  0.05
## meanmlq     2 54 5.76 1.03    6.0    5.84 0.89 3.8   7   3.2 -0.61
##          kurtosis   se
## BASELINE    -1.05 0.16
## meanmlq     -0.82 0.14

Create a plot that visualizes meanmlq variable by the GROUP variable

library(ggplot2)
library(influence.ME)

Take a look at the residuals

residual <- lm(meanmlq ~ 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$meanmlq)) 
sel2 <- which(!is.na(data2$BASELINE))
data2$residual[intersect(sel1,sel2)] <- residual
qplot(GROUP, meanmlq, 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 meanmlq and the Residuals

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

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

Comparing Basline to Wave 2 and 3 by Group.

fullModel <- lme(meanmlq ~ 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
##   240.2404 259.0798 -113.1202
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept)  Residual
## StdDev:   0.5321759 0.4951252
## 
## Fixed effects: meanmlq ~ GROUP * WAVE + BASELINE 
##                  Value Std.Error DF   t-value p-value
## (Intercept)  1.6901896 0.3918256 66  4.313628  0.0001
## GROUP1       0.8795864 0.3380075 66  2.602269  0.0114
## WAVE         0.0773449 0.1454611 38  0.531722  0.5980
## BASELINE     0.6589066 0.0654276 66 10.070773  0.0000
## GROUP1:WAVE -0.0842401 0.2125839 38 -0.396268  0.6941
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.426                     
## WAVE        -0.484  0.590              
## BASELINE    -0.811  0.037 -0.032       
## GROUP1:WAVE  0.333 -0.869 -0.684  0.021
## 
## Standardized Within-Group Residuals:
##        Min         Q1        Med         Q3        Max 
## -2.4086341 -0.4440518  0.1101479  0.3570213  2.0486129 
## 
## Number of Observations: 109
## Number of Groups: 69
Table with P-value

|             |       Value|  Std.Error|  DF|     t-value|    p-value|
|:------------|-----------:|----------:|---:|-----------:|----------:|
|(Intercept)  |   1.6901896|  0.3918256|  66|   4.3136276|  0.0000549|
|GROUP1       |   0.8795864|  0.3380075|  66|   2.6022691|  0.0114235|
|WAVE         |   0.0773449|  0.1454611|  38|   0.5317219|  0.5980136|
|BASELINE     |   0.6589066|  0.0654276|  66|  10.0707734|  0.0000000|
|GROUP1:WAVE  |  -0.0842401|  0.2125839|  38|  -0.3962676|  0.6941241|

Table with confidence intervals

est. lower upper
(Intercept) 1.6901896 0.9260380 2.4543411
GROUP1 0.8795864 0.2203927 1.5387801
WAVE 0.0773449 -0.2102926 0.3649823
BASELINE 0.6589066 0.5313075 0.7865058
GROUP1:WAVE -0.0842401 -0.5046074 0.3361272