title: “GRIT - consistency (Duckworth & Quinn 2009) 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("GRIT4", "GRIT5", "GRIT6", "GRIT7")
scaleKey <- c(-1, -1, -1, -1)
data.test4$meanGRIT  <- 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 meanGRIT and ID Group and wave from dtat.test4 and create a new #dataset with only those variables.
data <- data.test4[,c("ID", "GROUP", "wave", "meanGRIT")]
#Use dcast to cnage from long-format data to wide format data
data <- dcast(data, ID + GROUP ~ wave, mean, value.var = "meanGRIT")
# 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 meanGRIT and wave 2 and 3 of meanGRIT. 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 compaGRIT Time 2 to Baseline) “wave 1” and then the second 89 we call “wave 2” which compaGRIT 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", "meanGRIT", "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
## 
## -- Imputation 3 --
## 
##   1  2  3  4  5  6  7  8  9 10 11
## 
## -- Imputation 4 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 5 --
## 
##   1  2  3  4  5
## 
## -- Imputation 6 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 7 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 8 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 9 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 10 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 11 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 12 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 13 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 14 --
## 
##   1  2  3  4  5
## 
## -- Imputation 15 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 16 --
## 
##   1  2  3  4  5
## 
## -- Imputation 17 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 18 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 19 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 20 --
## 
##   1  2  3  4
## 
## -- Imputation 21 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 22 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 23 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 24 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 25 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 26 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 27 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 28 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 29 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 30 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 31 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 32 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 33 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 34 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 35 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 36 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 37 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 38 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 39 --
## 
##   1  2  3  4  5  6  7  8  9
## 
## -- Imputation 40 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 41 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 42 --
## 
##   1  2  3  4  5  6  7  8
## 
## -- Imputation 43 --
## 
##   1  2  3  4  5  6
## 
## -- 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
## 
## -- Imputation 47 --
## 
##   1  2  3  4  5  6
## 
## -- Imputation 48 --
## 
##   1  2  3  4  5  6  7
## 
## -- Imputation 49 --
## 
##   1  2  3  4  5  6
## 
## -- 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(meanGRIT ~ 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.15934303 0.29989719  0.5693706 1.7493155     39 %
## GROUP1       0.01640603 0.29444777 -0.5614501 0.5942621     23 %
## WAVE        -0.08105241 0.15196584 -0.3802314 0.2181266     43 %
## BASELINE     0.69939410 0.05983226  0.5815330 0.8172552     46 %
## GROUP1:WAVE  0.05557702 0.19482781 -0.3272618 0.4384158     33 %
summary
##                 results         se     (lower    upper) missInfo
## (Intercept)  1.15934303 0.29989719  0.5693706 1.7493155     39 %
## GROUP1       0.01640603 0.29444777 -0.5614501 0.5942621     23 %
## WAVE        -0.08105241 0.15196584 -0.3802314 0.2181266     43 %
## BASELINE     0.69939410 0.05983226  0.5815330 0.8172552     46 %
## GROUP1:WAVE  0.05557702 0.19482781 -0.3272618 0.4384158     33 %
library(pander)

Table

## 
## ----------------------------------------------------------------
##      &nbsp;        results    se     (lower   upper)   missInfo 
## ----------------- --------- ------- -------- -------- ----------
##  **(Intercept)**    1.159   0.2999   0.5694   1.749      39 %   
## 
##    **GROUP1**      0.01641  0.2944  -0.5615   0.5943     23 %   
## 
##     **WAVE**      -0.08105   0.152  -0.3802   0.2181     43 %   
## 
##   **BASELINE**     0.6994   0.05983  0.5815   0.8173     46 %   
## 
##  **GROUP1:WAVE**   0.05558  0.1948  -0.3273   0.4384     33 %   
## ----------------------------------------------------------------

Check GRITults 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(meanGRIT ~ 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.15694460 0.30586279  3.78256081 1.816782e-04
## GROUP1       0.01657391 0.31425187  0.05274086 9.579471e-01
## WAVE        -0.08105241 0.16155547 -0.50170021 6.161962e-01
## BASELINE     0.70013473 0.05783327 12.10608877 4.705953e-26
## GROUP1:WAVE  0.05554933 0.20922137  0.26550507 7.907077e-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

## 
## ----------------------------------------------------------
##      &nbsp;        Value    Std. Error   t-stat   p-value 
## ----------------- -------- ------------ -------- ---------
##  **(Intercept)**   1.157      0.3059     3.783   0.0001817
## 
##    **GROUP1**     0.01657     0.3143    0.05274   0.9579  
## 
##     **WAVE**      -0.08105    0.1616    -0.5017   0.6162  
## 
##   **BASELINE**     0.7001    0.05783     12.11   4.706e-26
## 
##  **GROUP1:WAVE**  0.05555     0.2092     0.2655   0.7907  
## ----------------------------------------------------------

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

data1=MI$imputations[[1]]
library("Zelig")
zelig.fitdata1 <- zelig(meanGRIT ~ 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 
## -1.57501 -0.40980 -0.01146  0.43362  1.57539 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.34099    0.23386   5.734 4.28e-08 ***
## GROUP1      -0.02499    0.27058  -0.092    0.927    
## WAVE        -0.11207    0.12296  -0.911    0.363    
## BASELINE     0.65737    0.04013  16.379  < 2e-16 ***
## GROUP1:WAVE  0.08811    0.17104   0.515    0.607    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5702 on 173 degrees of freedom
## Multiple R-squared:  0.6087, Adjusted R-squared:  0.5997 
## F-statistic: 67.29 on 4 and 173 DF,  p-value: < 2.2e-16

Describe the meanGRIT 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 3.24 1.07   3.25    3.26 1.11   1   5     4 -0.08
## meanGRIT    2 86 3.30 0.88   3.24    3.30 0.88   1   5     4  0.01
##          kurtosis   se
## BASELINE    -0.80 0.12
## meanGRIT    -0.34 0.09
## -------------------------------------------------------- 
## group: 1
##          vars  n mean   sd median trimmed  mad min  max range  skew
## BASELINE    1 92 3.05 1.07   3.00    3.08 1.11   1 5.00  4.00 -0.12
## meanGRIT    2 92 3.28 0.92   3.25    3.28 1.11   1 5.47  4.47  0.10
##          kurtosis   se
## BASELINE    -0.84 0.11
## meanGRIT    -0.64 0.10

Create a plot that visualizes meanGRIT 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(meanGRIT ~ 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$meanGRIT)) 
sel2 <- which(!is.na(data1$BASELINE))
data1$residual[intersect(sel1,sel2)] <- residual
qplot(GROUP, meanGRIT, 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 measuGRIT on dataset Randomly Selected Imputed Data ======================================================== Graphing the Two-Way Interaction. Both meanGRIT and the residuals

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

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

Comparing Basline to Wave 2 and 3 by Group.

fullModeldata1 <- lme(meanGRIT ~ 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 GRITults on this random Imputation model
GRITults

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
##   302.6932 324.9657 -144.3466
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept)  Residual
## StdDev:   0.3306978 0.4545128
## 
## Fixed effects: meanGRIT ~ GROUP * WAVE + BASELINE 
##                  Value  Std.Error DF   t-value p-value
## (Intercept)  1.3385835 0.22360000 87  5.986509  0.0000
## GROUP1      -0.0248259 0.23018777 87 -0.107851  0.9144
## WAVE        -0.1120743 0.09942917 86 -1.127177  0.2628
## BASELINE     0.6581128 0.04648887 86 14.156353  0.0000
## GROUP1:WAVE  0.0880940 0.13830519 86  0.636954  0.5258
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.561                     
## WAVE        -0.667  0.648              
## BASELINE    -0.673  0.044  0.000       
## GROUP1:WAVE  0.484 -0.901 -0.719 -0.006
## 
## Standardized Within-Group Residuals:
##         Min          Q1         Med          Q3         Max 
## -2.46938005 -0.66755116  0.02984241  0.66884743  2.87885954 
## 
## Number of Observations: 178
## Number of Groups: 89

Another random selected imputation

data10=MI$imputations[[10]]
library("Zelig")
zelig.fitdata10 <- zelig(meanGRIT ~ 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 
## -1.64171 -0.32911  0.01815  0.34502  1.81787 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.28087    0.24808   5.163 6.62e-07 ***
## GROUP1       0.02909    0.28640   0.102   0.9192    
## WAVE        -0.29485    0.13018  -2.265   0.0247 *  
## BASELINE     0.72399    0.04276  16.930  < 2e-16 ***
## GROUP1:WAVE  0.16164    0.18107   0.893   0.3733    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.6036 on 173 degrees of freedom
## Multiple R-squared:  0.6309, Adjusted R-squared:  0.6224 
## F-statistic: 73.93 on 4 and 173 DF,  p-value: < 2.2e-16

Describe the meanGRIT 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 3.24 1.07   3.25    3.26 1.11   1   5     4 -0.08
## meanGRIT    2 86 3.18 1.02   3.16    3.19 1.15   1   5     4 -0.08
##          kurtosis   se
## BASELINE    -0.80 0.12
## meanGRIT    -0.82 0.11
## -------------------------------------------------------- 
## group: 1
##          vars  n mean   sd median trimmed  mad  min  max range  skew
## BASELINE    1 92 3.08 1.06   3.00    3.12 1.11 1.00 5.00   4.0 -0.20
## meanGRIT    2 92 3.34 0.94   3.29    3.34 1.05 0.81 5.41   4.6 -0.05
##          kurtosis   se
## BASELINE    -0.75 0.11
## meanGRIT    -0.34 0.10

Create a plot that visualizes meanGRIT variable by the GROUP variable

library(ggplot2)
library(influence.ME)

Take a look at the residuals

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

Plot of the difference between intervention and control groups.

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

Two way repeated measuGRIT ======================================================== Graphing the Two-Way Interaction. Both meanGRIT and the residuals

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

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

Comparing Basline to Wave 2 and 3 by Group.

fullModeldata10 <- lme(meanGRIT ~ 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 GRITults on this random Imputation model
GRITults

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
##   332.1536 354.4261 -159.0768
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept)  Residual
## StdDev:   0.2349822 0.5466981
## 
## Fixed effects: meanGRIT ~ GROUP * WAVE + BASELINE 
##                  Value  Std.Error DF   t-value p-value
## (Intercept)  1.2795604 0.24338969 87  5.257250  0.0000
## GROUP1       0.0291647 0.26797442 87  0.108834  0.9136
## WAVE        -0.2948542 0.11959562 86 -2.465426  0.0157
## BASELINE     0.7243949 0.04596779 86 15.758749  0.0000
## GROUP1:WAVE  0.1616281 0.16635520 86  0.971584  0.3340
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.588                     
## WAVE        -0.737  0.669              
## BASELINE    -0.612  0.031  0.000       
## GROUP1:WAVE  0.533 -0.931 -0.719 -0.005
## 
## Standardized Within-Group Residuals:
##          Min           Q1          Med           Q3          Max 
## -2.700394035 -0.546642751  0.004482712  0.569917627  2.994565855 
## 
## Number of Observations: 178
## Number of Groups: 89

Another random selected imputation

data15=MI$imputations[[15]]
library("Zelig")
zelig.fitdata15 <- zelig(meanGRIT ~ 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 
## -1.72585 -0.34142  0.01828  0.38736  1.54662 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.01724    0.22112   4.600 8.12e-06 ***
## GROUP1       0.06330    0.25546   0.248    0.805    
## WAVE        -0.01650    0.11611  -0.142    0.887    
## BASELINE     0.72036    0.03806  18.928  < 2e-16 ***
## GROUP1:WAVE -0.01109    0.16150  -0.069    0.945    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5384 on 173 degrees of freedom
## Multiple R-squared:  0.6747, Adjusted R-squared:  0.6672 
## F-statistic: 89.72 on 4 and 173 DF,  p-value: < 2.2e-16

Describe the meanGRIT 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 3.24 1.07   3.25    3.26 1.11   1 5.00  4.00 -0.08
## meanGRIT    2 86 3.33 0.95   3.25    3.35 1.11   1 5.09  4.09 -0.13
##          kurtosis   se
## BASELINE    -0.80 0.12
## meanGRIT    -0.49 0.10
## -------------------------------------------------------- 
## group: 1
##          vars  n mean   sd median trimmed  mad min max range  skew
## BASELINE    1 92 3.09 1.07   3.00    3.13 1.11   1   5     4 -0.21
## meanGRIT    2 92 3.26 0.92   3.23    3.28 1.09   1   5     4 -0.13
##          kurtosis   se
## BASELINE    -0.77 0.11
## meanGRIT    -0.73 0.10

Create a plot that visualizes meanGRIT variable by the GROUP variable

library(ggplot2)
library(influence.ME)

Take a look at the residuals

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

Plot of the difference between intervention and control groups.

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

Two way repeated measuGRIT ======================================================== Graphing the Two-Way Interaction. Both meanGRIT and the residuals

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

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

Comparing Basline to Wave 2 and 3 by Group.

fullModeldata15 <- lme(meanGRIT ~ 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 GRITults on this random Imputation model
GRITults

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
##   286.7015 308.974 -136.3507
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept)  Residual
## StdDev:   0.2776785 0.4523224
## 
## Fixed effects: meanGRIT ~ GROUP * WAVE + BASELINE 
##                  Value  Std.Error DF   t-value p-value
## (Intercept)  1.0180171 0.21364293 87  4.765040  0.0000
## GROUP1       0.0632497 0.22581944 87  0.280090  0.7801
## WAVE        -0.0165045 0.09895001 86 -0.166796  0.8679
## BASELINE     0.7201186 0.04292232 86 16.777254  0.0000
## GROUP1:WAVE -0.0110873 0.13764042 86 -0.080552  0.9360
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.569                     
## WAVE        -0.695  0.657              
## BASELINE    -0.651  0.036  0.000       
## GROUP1:WAVE  0.505 -0.915 -0.719 -0.008
## 
## Standardized Within-Group Residuals:
##         Min          Q1         Med          Q3         Max 
## -2.88006669 -0.57169743  0.02207634  0.65203590  2.89266965 
## 
## Number of Observations: 178
## Number of Groups: 89

Another randomly selected imputation

data25=MI$imputations[[25]]

library("Zelig")
zelig.fitdata25 <- zelig(meanGRIT ~ 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 
## -1.62951 -0.33499  0.01219  0.35045  1.66484 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.02426    0.25069   4.086 6.71e-05 ***
## GROUP1       0.14247    0.28989   0.491    0.624    
## WAVE        -0.11154    0.13178  -0.846    0.398    
## BASELINE     0.73963    0.04304  17.183  < 2e-16 ***
## GROUP1:WAVE  0.03124    0.18330   0.170    0.865    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.611 on 173 degrees of freedom
## Multiple R-squared:  0.6319, Adjusted R-squared:  0.6234 
## F-statistic: 74.26 on 4 and 173 DF,  p-value: < 2.2e-16

Describe the meanGRIT 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 3.24 1.07   3.25    3.26 1.11 1.00   5  4.00 -0.08
## meanGRIT    2 86 3.25 1.03   3.25    3.29 1.11 0.28   5  4.72 -0.37
##          kurtosis   se
## BASELINE    -0.80 0.12
## meanGRIT    -0.29 0.11
## -------------------------------------------------------- 
## group: 1
##          vars  n mean   sd median trimmed  mad min  max range  skew
## BASELINE    1 92 3.08 1.07   3.00    3.12 1.11   1 5.00  4.00 -0.16
## meanGRIT    2 92 3.32 0.97   3.36    3.32 0.96   1 5.62  4.62  0.00
##          kurtosis   se
## BASELINE    -0.80 0.11
## meanGRIT    -0.48 0.10

Create a plot that visualizes meanGRIT variable by the GROUP variable

library(ggplot2)
library(influence.ME)

Take a look at the residuals

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

Plot of the difference between intervention and control groups.

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

Two way repeated measuGRIT ======================================================== Graphing the Two-Way Interaction. Both meanGRIT and the residuals

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

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

Comparing Basline to Wave 2 and 3 by Group.

fullModeldata25 <- lme(meanGRIT ~ 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 GRITults on this random Imputation model
GRITults

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
##   336.0317 358.3042 -161.0159
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept)  Residual
## StdDev:   0.2497038 0.5481907
## 
## Fixed effects: meanGRIT ~ GROUP * WAVE + BASELINE 
##                  Value  Std.Error DF   t-value p-value
## (Intercept)  1.0242108 0.24537135 87  4.174126  0.0001
## GROUP1       0.1424683 0.26925425 87  0.529122  0.5981
## WAVE        -0.1115393 0.11992214 86 -0.930097  0.3549
## BASELINE     0.7396451 0.04658832 86 15.876194  0.0000
## GROUP1:WAVE  0.0312392 0.16680762 86  0.187277  0.8519
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.583                     
## WAVE        -0.733  0.668              
## BASELINE    -0.615  0.026  0.000       
## GROUP1:WAVE  0.526 -0.929 -0.719  0.001
## 
## Standardized Within-Group Residuals:
##         Min          Q1         Med          Q3         Max 
## -2.72003201 -0.55495569  0.05457448  0.51854760  2.71113625 
## 
## Number of Observations: 178
## Number of Groups: 89

Check assumptions on model without any imputations

Describe the meanGRIT variable by the GROUP variable

describeBy(data2[,3:4], group = data2$GROUP)
## group: 0
##          vars  n mean   sd median trimmed  mad min max range  skew
## BASELINE    1 86 3.24 1.07   3.25    3.26 1.11   1   5     4 -0.08
## meanGRIT    2 59 3.39 0.99   3.25    3.43 1.11   1   5     4 -0.19
##          kurtosis   se
## BASELINE    -0.80 0.12
## meanGRIT    -0.64 0.13
## -------------------------------------------------------- 
## group: 1
##          vars  n mean   sd median trimmed  mad min max range  skew
## BASELINE    1 88 3.06 1.08   3.00    3.09 1.11   1   5     4 -0.15
## meanGRIT    2 54 3.25 0.87   3.25    3.26 1.11   1   5     4 -0.08
##          kurtosis   se
## BASELINE    -0.81 0.11
## meanGRIT    -0.75 0.12

Create a plot that visualizes meanGRIT variable by the GROUP variable

library(ggplot2)
library(influence.ME)

Take a look at the residuals

residual <- lm(meanGRIT ~ 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$meanGRIT)) 
sel2 <- which(!is.na(data2$BASELINE))
data2$residual[intersect(sel1,sel2)] <- residual
qplot(GROUP, meanGRIT, 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 measuGRIT ======================================================== Graphing the Two-Way Interaction. Both meanGRIT and the residuals

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

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

Comparing Basline to Wave 2 and 3 by Group.

fullModel <- lme(meanGRIT ~ 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")
GRITults on Model with data that contains no imputations
GRITults

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
##   203.7835 222.623 -94.89176
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept)  Residual
## StdDev:   0.3721644 0.4651186
## 
## Fixed effects: meanGRIT ~ GROUP * WAVE + BASELINE 
##                  Value  Std.Error DF   t-value p-value
## (Intercept)  1.2209133 0.29048086 66  4.203077  0.0001
## GROUP1       0.0151365 0.30315410 66  0.049930  0.9603
## WAVE        -0.0909906 0.13361375 38 -0.680997  0.5000
## BASELINE     0.6858664 0.06198387 66 11.065241  0.0000
## GROUP1:WAVE  0.0278719 0.19574450 38  0.142389  0.8875
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.524                     
## WAVE        -0.636  0.610              
## BASELINE    -0.708  0.065  0.000       
## GROUP1:WAVE  0.430 -0.898 -0.683  0.006
## 
## Standardized Within-Group Residuals:
##         Min          Q1         Med          Q3         Max 
## -2.38281415 -0.52105141  0.03116737  0.52134455  2.74694895 
## 
## Number of Observations: 109
## Number of Groups: 69

Table with confidence intervals

Table with confidence intervals

## 
## ------------------------------------------
##      &nbsp;        lower    est.    upper 
## ----------------- ------- -------- -------
##  **(Intercept)**  0.6544   1.221    1.787 
## 
##    **GROUP1**     -0.5761 0.01514  0.6064 
## 
##     **WAVE**      -0.3552 -0.09099 0.1732 
## 
##   **BASELINE**     0.565   0.6859  0.8067 
## 
##  **GROUP1:WAVE**  -0.3592 0.02787  0.4149 
## ------------------------------------------

Table with p-values

## 
## ---------------------------------------------------------------
##      &nbsp;        Value    Std.Error   DF   t-value   p-value 
## ----------------- -------- ----------- ---- --------- ---------
##  **(Intercept)**   1.221     0.2905     66    4.203   8.087e-05
## 
##    **GROUP1**     0.01514    0.3032     66   0.04993   0.9603  
## 
##     **WAVE**      -0.09099   0.1336     38   -0.681      0.5   
## 
##   **BASELINE**     0.6859    0.06198    66    11.07   1.109e-16
## 
##  **GROUP1:WAVE**  0.02787    0.1957     38   0.1424    0.8875  
## ---------------------------------------------------------------