Repeated Measures for Sense of Identity

#Loading the dataset that has been reset into a long version
data.test4 <- read.csv("/Volumes/TOSHIBA EXT/Dropbox/ADULT STUDY/adult_study011615.csv")
# Load the psych package
library(psych)
items <- grep("APSI[0-8]", names(data.test4), value=TRUE)
items
## [1] "APSI1" "APSI2" "APSI3" "APSI4" "APSI5" "APSI6" "APSI7" "APSI8"
scaleKey <- c(1,1,1,1,1,-1,1,1)
data.test4[,items] <- apply(data.test4[,items], 2, as.numeric)
data.test4$meanAPSI <- scoreItems(scaleKey, items = data.test4[, items])$score
library(reshape2); library(car)
## Warning: package 'car' was built under R version 3.1.2
## 
## Attaching package: 'car'
## 
## The following object is masked from 'package:psych':
## 
##     logit
data <- data.test4[,c("ID", "GROUP", "wave", "meanAPSI")]
data <- dcast(data, ID + GROUP ~ wave, mean, value.var = "meanAPSI")
write.csv(data, file = "Data.csv")
data[,3:5] <- apply(data[,3:5],2,function(x) recode(x, "NaN = NA") )

For lme to work GROUP and ID need to be seen as factors

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", "meanASPI", "WAVE")
data2 <- data2[-c(which(data2$GROUP ==2)),]
write.csv(data2, file = "Data2.csv")
data2$GROUP <-as.factor(data2$GROUP)
data2$ID <-as.factor(data2$ID)


# Load the psych package
library(psych)

Describe the MLQ 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.96 0.63   4.00    4.00 0.56 2.38   5  2.62 -0.48
## meanASPI    2 59 4.09 0.65   4.12    4.14 0.56 2.25   5  2.75 -0.68
##          kurtosis   se
## BASELINE    -0.17 0.07
## meanASPI     0.03 0.08
## -------------------------------------------------------- 
## group: 1
##          vars  n mean   sd median trimmed  mad  min max range  skew
## BASELINE    1 80 3.76 0.81   3.75    3.80 0.93 1.62   5  3.38 -0.38
## meanASPI    2 51 4.32 0.49   4.38    4.35 0.56 3.00   5  2.00 -0.49
##          kurtosis   se
## BASELINE    -0.29 0.09
## meanASPI    -0.51 0.07

Create a plot that visualizes MLQ variable by the GROUP variable

library(ggplot2)
## 
## Attaching package: 'ggplot2'
## 
## The following object is masked from 'package:psych':
## 
##     %+%
qplot(GROUP, meanASPI, data=data2, geom="boxplot")
## Warning: Removed 60 rows containing non-finite values (stat_boxplot).

plot of chunk unnamed-chunk-5

# Load the nlme package
library(nlme)

Two way repeated measures

Graphing the Two-Way Interaction.

with(data2, boxplot(meanASPI ~ WAVE + GROUP))

plot of chunk unnamed-chunk-6

I am not sure if I am doing this right

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

We again the significance of our models by comparing them from the baseline model using the anova() function.

summary(fullModel)
## Linear mixed-effects model fit by maximum likelihood
##  Data: data2 
##     AIC   BIC logLik
##   115.6 134.3 -50.82
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept) Residual
## StdDev:      0.2911   0.2922
## 
## Fixed effects: meanASPI ~ GROUP * WAVE + BASELINE 
##               Value Std.Error DF t-value p-value
## (Intercept)  1.5363   0.30383 63   5.056  0.0000
## GROUP1       0.5038   0.19960 63   2.524  0.0141
## WAVE         0.0928   0.08552 38   1.085  0.2848
## BASELINE     0.5888   0.06911 63   8.520  0.0000
## GROUP1:WAVE -0.0842   0.12611 38  -0.668  0.5083
##  Correlation: 
##             (Intr) GROUP1 WAVE   BASELI
## GROUP1      -0.337                     
## WAVE        -0.331  0.585              
## BASELINE    -0.898  0.048 -0.061       
## GROUP1:WAVE  0.214 -0.872 -0.679  0.054
## 
## Standardized Within-Group Residuals:
##       Min        Q1       Med        Q3       Max 
## -2.152996 -0.579488 -0.002915  0.592138  2.408125 
## 
## Number of Observations: 106
## Number of Groups: 66

Table with P-values

Value Std.Error DF t-value p-value
(Intercept) 1.5363 0.3038 63.0000 5.0564 0.0000
GROUP1 0.5038 0.1996 63.0000 2.5241 0.0141
WAVE 0.0928 0.0855 38.0000 1.0850 0.2848
BASELINE 0.5888 0.0691 63.0000 8.5198 0.0000
GROUP1:WAVE -0.0842 0.1261 38.0000 -0.6678 0.5083

Table with confidence intervals

lower est. upper
(Intercept) 0.9436 1.5363 2.1289
GROUP1 0.1145 0.5038 0.8932
WAVE -0.0762 0.0928 0.2618
BASELINE 0.4540 0.5888 0.7236
GROUP1:WAVE -0.3334 -0.0842 0.1650