##Basic Design:

This code conducts a mixed levels effects analysis:

Group-level design (2x2 cell):

                             AE                              UAA
            ----------------------------------------------------------------  
   Pre (1) | Parameter Estimate @ time1,   | Parameter Estimate @ time1,   |  
           | Parameter Estimate @ time2... | Parameter Estimate @ time2... |  
           | Parameter Estimate @ time 11  | Parameter Estimate @ time 11  |  
           |---------------------------------------------------------------|  
  Post (2) | Parameter Estimate @ time1,   | Parameter Estimate @ time1,   |   
           | Parameter Estimate @ time2... | Parameter Estimate @ time2... |  
           | Parameter Estimate @ time 11  | Parameter Estimate @ time 11  |  
            ----------------------------------------------------------------  

With:
Time (Pre =1 or Post =2) = within subject or repeated measures factor (fixed factor)
Intervention (AE or UAA group) = between subject factor (fixed factor)

@ Subject-level:

Subject_ID = blocking factor (random factor)

Parameter Estimate at each time point = measured (dependent) variable

##References

  1. https://ase.tufts.edu/gsc/gradresources/guidetomixedmodelsinr/mixed%20model%20guide.html
  2. https://www.theanalysisfactor.com/the-difference-between-crossed-and-nested-factors/
  3. https://www.r-bloggers.com/how-to-get-the-frequency-table-of-a-categorical-variable-as-a-data-frame-in-r/
  4. https://stats.stackexchange.com/questions/98958/plots-to-illustrate-results-of-linear-mixed-effect-model
  5. https://stackoverflow.com/questions/31075407/plot-mixed-effects-model-in-ggplot
  6. https://stats.stackexchange.com/questions/115090/why-do-i-get-zero-variance-of-a-random-effect-in-my-mixed-model-despite-some-va

##Library

## Loading required package: Matrix
## Loading required package: carData
## Registered S3 methods overwritten by 'car':
##   method                          from
##   influence.merMod                lme4
##   cooks.distance.influence.merMod lme4
##   dfbeta.influence.merMod         lme4
##   dfbetas.influence.merMod        lme4

##Assumptions (adapted from Reference 1)

STEP 1: What distribution best fits the data?

We want to pick the distribution for which the largest number of observations falls between the dashed lines.

Standard distributions tested:

  1. Normal: Syntax: qqp(dataset$columnName, “norm”)

  2. Lognormal: Syntax: qqp(dataset$columnName, “lnorm”)

  3. Neg binomial: Syntax: fitdistr(dataset$columnName, “Negative Binomial”)

  4. Poisson: Syntax: fitdistr(dataset$columnName, “Poisson”)

  5. Gamma: Syntax: fitdistr(dataset$columnName, “gamma”)


SUMMARY CHECKLIST FOR STEP 1 (current study):

Draft Checklist: What distribution best fits the data?

  1. qqp(dataset$columnName, “norm”)

  2. qqp(dataset$columnName, “lnorm”)

  3. fitdistr(dataset$columnName, “Negative Binomial”)
    A neg binomial model doesn’t make sense here, since a negative binomial is a kind of count model. The response is supposed to be counts. A count, by definition, cannot be a fractional value (i.e.,count=non-negative whole numbers).

  4. fitdistr(dataset$columnName, “Poisson”)
    Also, doesn’t make sense here, since a poisson distribution can only handle positive whole numbers.

  5. [add 1 to dataset$columnName for gamma dist. to work; gama dist. requires values >=0]
  • fitdistr(dataset$columnName+1, “gamma”)
  • qqp(dataset$columnName+1, “gamma”, shape = gamma$estimate[[1]], rate=gamma$estimate[[2]])


FINAL CHECKLIST [For the current study]: What distribution best fits the data?

  1. qqp(dataset$columnName, “norm”)

  2. qqp(dataset$columnName, “lnorm”)

  3. gamma func:
  • fitdistr(dataset$Add1toColumnName, “gamma”)
  • qqp(dataset$Add1toColumnName, “gamma”, shape = gamma$estimate[[1]], rate = gamma$estimate[[2]])




STEP 2: How should the mixed model be fit to the data?

First, a note: if your data best fit the lognormal distribution, do not transform them. This is true for any type of transformation you might apply to your data to make them normal. If you can transform your data to normality, common wisdom says you should use the transformed data.More recent statistics literature has entirely changed stance on this matter, however, because transformation makes interpretation of model results more difficult, and it makes mischief with the variance of the transformed variable. Even if your data are transformable to normality, they are still not normal, and you should move on to tnon-linear models.

If data are normally distributed:

  1. The first argument to the function is a formula that takes the form y ~ x1 + x2 … etc., where y is the response variable and x1, x2, etc. are explanatory variables.

  2. Random effects are added in with the explanatory variables.

  3. Crossed random effects take the form (1 | r1) + (1 | r2), while nested random effects take the form (1 | r1 / r2).

  4. The next argument is where we designate the data frame your variables come from.

  5. The next argument allows us to designate whether the mixed model will estimate the parameters using maximum likelihood or restricted maximum likelihood.


SUMMARY CHECKLIST FOR STEP 2:

Draft Checklist: How should the mixed model be fit to the data?

  1. Fitting the data: are the data normally distributed? -> If no, consider nlme. If yes, use lmer.

  2. Should we include crossed factors and/or nested factors? For the current study, because subjects are crossed across time (-although they are nested within group-), we treat them as crossed factors. (Reference 2)

  3. Should we use REML or ML?


Subchecklist:

  1. Nested random effects? -> If no (for current study: No), then go to step 2

  2. Only one random effect? -> If yes (for current study: Yes, subject) then go to step 3 [If no, do nothing]

  3. Similar sample sizes? (or are data balanced?) -> If yes, then set REML to false (else do nothing).


FINAL Checklist [For the current study]: How should the mixed model be fit to the data?

  1. Fitting the data: are the data normally distributed? -> If no, consider nlme. If yes, use lmer.

  2. Should we use REML or ML? Are the data balanced?/similar sample sizes for each fixed factor? -> If yes, then set REML to false (else do nothing).




STEP 3: Interpreting Results

  1. First we get some measures of model fit, including AIC, BIC, log likelihood, and deviance.

  2. Then we get an estimate of the variance explained by the random effect. This number is important, because if it’s indistinguishable from zero, then your random effect probably doesn’t matter and you can go ahead and do a regular linear model instead. The lesson from this model output is that although there is “obviously” variation in subject performance, the extent of this subject variation can be fully or virtually-fully explained by just the residual variance term alone. There is not enough additional subject-level variation to warrant adding an additional subject-level random effect to explain all the observed variation.
  1. Next we have estimates of the fixed effects, with standard errors. Some journals like you to report the results of these models as effect sizes with confidence intervals. Some journals want you to report p-values.The creators of the lme4 package are philosophically opposed to p-values, so we use anova from library(car). The Anova function does a Wald test, which tells us how confident we are of our estimate of the effect of groupID and time on time1, and the p-value tells us that we should not be confident at all.: Syntax: Anova(lmm)


SUMMARY CHECKLIST FOR STEP 3 (current study):

FINAL Checklist [For the current study]: How do we interpret the results?

  1. Is the variance related to the random effect close to zero? If not, consider a non-linear model.

  2. For p-value estimates of the fixed effects, use Anova(lmm). Note that for significant effects, if groupIDUAA:timeIDpre > 0, then as groupID changes to AE and timeID changes to post, AE increases (symbolized as AE^ in the Summary Table Tab). Put differently, AE increases from Pre to Post, while UAA decreases from Pre to Post.


Dataset

MixedANOVA_BraverSeed<-read.csv(file="//Volumes//aishwar2_ACT//ACT//fMRITasks//AX_CPT//output//preAndPost_combined_form2//BraverSeeds//BA6_supFrontal_R_MNIx28yneg15z64.csv",
                            head=TRUE,sep=',', 
                            na.strings = "NA",
                            stringsAsFactors=TRUE)

str(MixedANOVA_BraverSeed)
## 'data.frame':    264 obs. of  16 variables:
##  $ subID  : Factor w/ 142 levels "sub01","sub04",..: 16 17 18 21 23 25 26 27 29 33 ...
##  $ groupID: Factor w/ 2 levels "AE","UAA": 1 1 1 1 1 1 1 1 1 1 ...
##  $ timeID : Factor w/ 2 levels "post","pre": 2 2 2 2 2 2 2 2 2 2 ...
##  $ seeds  : Factor w/ 1 level "Braver": 1 1 1 1 1 1 1 1 1 1 ...
##  $ ROI    : Factor w/ 1 level "BA6_supFrontal_R_MNIx28yneg15z64": 1 1 1 1 1 1 1 1 1 1 ...
##  $ time1  : num  0.00315 -0.10988 0.07948 0.06653 0.08784 ...
##  $ time2  : num  0.03977 0.02363 -0.17853 0.00843 0.03645 ...
##  $ time3  : num  -1.07207 -0.81295 -0.44929 0.03546 0.00961 ...
##  $ time4  : num  -1.821 -1.247 -0.693 -0.134 0.226 ...
##  $ time5  : num  -1.781 -1.346 -0.896 -0.119 0.125 ...
##  $ time6  : num  -0.6984 -0.7283 -0.2784 0.1047 0.0885 ...
##  $ time7  : num  -0.1089 -0.1431 -0.1117 0.0491 0.1261 ...
##  $ time8  : num  0.1048 -0.196 -0.0136 0.1967 -0.0172 ...
##  $ time9  : num  0.08729 -0.00771 -0.05872 0.17966 -0.06321 ...
##  $ time10 : num  0.00927 -0.07697 0.01874 0.10187 0.19044 ...
##  $ time11 : num  0.106 -0.0858 -0.0111 0.1648 -0.0148 ...

Timepoints

Time3

  • STEP1 Checklist:
MixedANOVA_BraverSeed$t3 <- MixedANOVA_BraverSeed$time3 + 1
qqp(MixedANOVA_BraverSeed$t3, "norm")

## [1] 237  54
qqp(MixedANOVA_BraverSeed$t3, "lnorm")

## [1] 237  54
# For the gamma distr, adding 1 still gives error, so removed this.
#gamma <- fitdistr(MixedANOVA_BraverSeed$t3, "gamma")
#qqp(MixedANOVA_BraverSeed$t3, "gamma", shape = gamma$estimate[[1]], rate = gamma$estimate[[2]])

#####Verdict: Normal distribution is best suited.


  • STEP2 Checklist:
# 1. Use lmer 
# 2a. Check if data are balanced across groups:
count(MixedANOVA_BraverSeed, 'groupID')
##   groupID freq
## 1      AE  130
## 2     UAA  134
# 2b. Check if data are balanced across time:
count(MixedANOVA_BraverSeed, 'timeID') 
##   timeID freq
## 1   post  131
## 2    pre  133

#####Verdict: Use lmer, set REML=false.


  • Model:
lmm <- lmer(time3 ~ groupID * timeID + (1 | subID), data = MixedANOVA_BraverSeed,
            REML = FALSE)
summary(lmm)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: time3 ~ groupID * timeID + (1 | subID)
##    Data: MixedANOVA_BraverSeed
## 
##      AIC      BIC   logLik deviance df.resid 
##    941.0    962.5   -464.5    929.0      258 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -5.3838 -0.6214  0.0919  0.5792  3.0111 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subID    (Intercept) 0.1846   0.4296  
##  Residual             1.7995   1.3415  
## Number of obs: 264, groups:  subID, 142
## 
## Fixed effects:
##                      Estimate Std. Error t value
## (Intercept)            0.1828     0.1733   1.055
## groupIDUAA            -0.4477     0.2461  -1.820
## timeIDpre             -0.4603     0.2364  -1.947
## groupIDUAA:timeIDpre   0.8195     0.3316   2.472
## 
## Correlation of Fixed Effects:
##             (Intr) grIDUAA tmIDpr
## groupIDUAA  -0.704               
## timeIDpre   -0.670  0.472        
## grpIDUAA:ID  0.478 -0.679  -0.713


#####Verdict: Use lmer, set REML=false.


  • STEP3 Checklist:
#1. Close to 0, linear model okay.
# 2.
Anova(lmm)
## Analysis of Deviance Table (Type II Wald chisquare tests)
## 
## Response: time3
##                 Chisq Df Pr(>Chisq)  
## groupID        0.0374  1    0.84671  
## timeID         0.0700  1    0.79139  
## groupID:timeID 6.1092  1    0.01345 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


#####Verdict: linear-model okay, significant interactions (p=0.01). Note that groupIDUAA:timeIDpre > 0. That is, as groupID changes to AE and timeID changes to post, AE increases (symbolized as AE^ in the Summary Table Tab). Put differently, AE increases from Pre to Post, while UAA decreases from Pre to Post.

Time4

  • STEP1 Checklist:
MixedANOVA_BraverSeed$t4 <- MixedANOVA_BraverSeed$time4 + 1
qqp(MixedANOVA_BraverSeed$t4, "norm")

## [1] 237  54
qqp(MixedANOVA_BraverSeed$t4, "lnorm")

## [1] 237  54
# For the gamma distr, adding 1 still gives error, so removed this.
#gamma <- fitdistr(MixedANOVA_BraverSeed$t4, "gamma")
#qqp(MixedANOVA_BraverSeed$t4, "gamma", shape = gamma$estimate[[1]], rate = gamma$estimate[[2]])

#####Verdict: Normal distribution is best suited.


  • STEP2 Checklist:
# 1. Use lmer 
# 2a. Check if data are balanced across groups:
count(MixedANOVA_BraverSeed, 'groupID')
##   groupID freq
## 1      AE  130
## 2     UAA  134
# 2b. Check if data are balanced across time:
count(MixedANOVA_BraverSeed, 'timeID') 
##   timeID freq
## 1   post  131
## 2    pre  133

#####Verdict: Use lmer, set REML=false.


  • Model:
lmm <- lmer(time4 ~ groupID * timeID + (1 | subID), data = MixedANOVA_BraverSeed,
            REML = FALSE)
summary(lmm)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: time4 ~ groupID * timeID + (1 | subID)
##    Data: MixedANOVA_BraverSeed
## 
##      AIC      BIC   logLik deviance df.resid 
##   1192.2   1213.7   -590.1   1180.2      258 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -5.6891 -0.5692  0.0658  0.5891  3.0472 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subID    (Intercept) 0.4366   0.6608  
##  Residual             4.6979   2.1675  
## Number of obs: 264, groups:  subID, 142
## 
## Fixed effects:
##                      Estimate Std. Error t value
## (Intercept)            0.4667     0.2788   1.674
## groupIDUAA            -0.7577     0.3959  -1.914
## timeIDpre             -0.9172     0.3817  -2.403
## groupIDUAA:timeIDpre   1.3358     0.5355   2.494
## 
## Correlation of Fixed Effects:
##             (Intr) grIDUAA tmIDpr
## groupIDUAA  -0.704               
## timeIDpre   -0.673  0.474        
## grpIDUAA:ID  0.480 -0.681  -0.713


#####Verdict: Use lmer, set REML=false.


  • STEP3 Checklist:
#1. Close to 0, linear model okay.
# 2.
Anova(lmm)
## Analysis of Deviance Table (Type II Wald chisquare tests)
## 
## Response: time4
##                 Chisq Df Pr(>Chisq)  
## groupID        0.0857  1    0.76973  
## timeID         0.7935  1    0.37306  
## groupID:timeID 6.2214  1    0.01262 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


#####Verdict: linear-model okay, significant interactions (p=0.01). Note that groupIDUAA:timeIDpre > 0. That is, as groupID changes to AE and timeID changes to post, AE increases (symbolized as AE^ in the Summary Table Tab). Put differently, AE increases from Pre to Post, while UAA decreases from Pre to Post.

Time5

  • STEP1 Checklist:
MixedANOVA_BraverSeed$t5 <- MixedANOVA_BraverSeed$time5 + 1
qqp(MixedANOVA_BraverSeed$t5, "norm")

## [1] 237  54
qqp(MixedANOVA_BraverSeed$t5, "lnorm")

## [1] 237  54
# For the gamma distr, adding 1 still gives error, so removed this.
# gamma <- fitdistr(MixedANOVA_BraverSeed$t5, "gamma")
# qqp(MixedANOVA_BraverSeed$t5, "gamma", shape = gamma$estimate[[1]], rate = gamma$estimate[[2]])

#####Verdict: Normal distribution is best suited.


  • STEP2 Checklist:
# 1. Use lmer 
# 2a. Check if data are balanced across groups:
count(MixedANOVA_BraverSeed, 'groupID')
##   groupID freq
## 1      AE  130
## 2     UAA  134
# 2b. Check if data are balanced across time:
count(MixedANOVA_BraverSeed, 'timeID') 
##   timeID freq
## 1   post  131
## 2    pre  133

#####Verdict: Use lmer, set REML=false.


  • Model:
lmm <- lmer(time5 ~ groupID * timeID + (1 | subID), data = MixedANOVA_BraverSeed,
            REML = FALSE)
summary(lmm)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: time5 ~ groupID * timeID + (1 | subID)
##    Data: MixedANOVA_BraverSeed
## 
##      AIC      BIC   logLik deviance df.resid 
##   1181.8   1203.3   -584.9   1169.8      258 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -5.2637 -0.6072  0.0860  0.5883  2.9422 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subID    (Intercept) 0.3325   0.5766  
##  Residual             4.5973   2.1441  
## Number of obs: 264, groups:  subID, 142
## 
## Fixed effects:
##                      Estimate Std. Error t value
## (Intercept)            0.3507     0.2733   1.283
## groupIDUAA            -0.7503     0.3879  -1.934
## timeIDpre             -0.8198     0.3773  -2.173
## groupIDUAA:timeIDpre   1.3551     0.5294   2.560
## 
## Correlation of Fixed Effects:
##             (Intr) grIDUAA tmIDpr
## groupIDUAA  -0.704               
## timeIDpre   -0.679  0.478        
## grpIDUAA:ID  0.484 -0.687  -0.713


#####Verdict: Use lmer, set REML=false.


  • STEP3 Checklist:
#1. Close to 0, linear model okay.
# 2.
Anova(lmm)
## Analysis of Deviance Table (Type II Wald chisquare tests)
## 
## Response: time5
##                 Chisq Df Pr(>Chisq)  
## groupID        0.0579  1    0.80989  
## timeID         0.2465  1    0.61952  
## groupID:timeID 6.5513  1    0.01048 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


#####Verdict: linear-model okay, significant interactions (p=0.01). Note that groupIDUAA:timeIDpre > 0. That is, as groupID changes to AE and timeID changes to post, AE increases (symbolized as AE^ in the Summary Table Tab). Put differently, AE increases from Pre to Post, while UAA decreases from Pre to Post.

Time6

  • STEP1 Checklist:
MixedANOVA_BraverSeed$t6 <- MixedANOVA_BraverSeed$time6 + 1
qqp(MixedANOVA_BraverSeed$t6, "norm")

## [1] 237  54
qqp(MixedANOVA_BraverSeed$t6, "lnorm")

## [1] 237  54
# For the gamma distr, adding 1 still gives error, so removed this.
# gamma <- fitdistr(MixedANOVA_BraverSeed$t6, "gamma")
# qqp(MixedANOVA_BraverSeed$t6, "gamma", shape = gamma$estimate[[1]], rate = gamma$estimate[[2]])

#####Verdict: Normal distribution is best suited.


  • STEP2 Checklist:
# 1. Use lmer 
# 2a. Check if data are balanced across groups:
count(MixedANOVA_BraverSeed, 'groupID')
##   groupID freq
## 1      AE  130
## 2     UAA  134
# 2b. Check if data are balanced across time:
count(MixedANOVA_BraverSeed, 'timeID') 
##   timeID freq
## 1   post  131
## 2    pre  133

#####Verdict: Use lmer, set REML=false.


  • Model:
lmm <- lmer(time6 ~ groupID * timeID + (1 | subID), data = MixedANOVA_BraverSeed,
            REML = FALSE)
summary(lmm)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: time6 ~ groupID * timeID + (1 | subID)
##    Data: MixedANOVA_BraverSeed
## 
##      AIC      BIC   logLik deviance df.resid 
##    794.5    815.9   -391.2    782.5      258 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -5.6154 -0.5895  0.0754  0.5596  3.0236 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subID    (Intercept) 0.1731   0.4161  
##  Residual             0.9734   0.9866  
## Number of obs: 264, groups:  subID, 142
## 
## Fixed effects:
##                      Estimate Std. Error t value
## (Intercept)            0.1001     0.1317   0.760
## groupIDUAA            -0.3190     0.1869  -1.707
## timeIDpre             -0.3332     0.1743  -1.912
## groupIDUAA:timeIDpre   0.6066     0.2444   2.482
## 
## Correlation of Fixed Effects:
##             (Intr) grIDUAA tmIDpr
## groupIDUAA  -0.704               
## timeIDpre   -0.650  0.458        
## grpIDUAA:ID  0.464 -0.659  -0.713


#####Verdict: Use lmer, set REML=false.


  • STEP3 Checklist:
#1. Close to 0, linear model okay.
# 2.
Anova(lmm)
## Analysis of Deviance Table (Type II Wald chisquare tests)
## 
## Response: time6
##                 Chisq Df Pr(>Chisq)  
## groupID        0.0090  1    0.92437  
## timeID         0.0407  1    0.84019  
## groupID:timeID 6.1611  1    0.01306 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


#####Verdict: linear-model okay, significant interactions (p=0.01). Note that groupIDUAA:timeIDpre > 0. That is, as groupID changes to AE and timeID changes to post, AE increases (symbolized as AE^ in the Summary Table Tab). Put differently, AE increases from Pre to Post, while UAA decreases from Pre to Post.

Graph_SignificantInteractions

Time3
lmm <- lmer(time3 ~ groupID * timeID + (1 | subID), data = MixedANOVA_BraverSeed,
            REML = FALSE)

MixedANOVA_BraverSeed$fit3 <- predict(lmm)
time_order <- c('pre', 'post') 

ggplot(MixedANOVA_BraverSeed, aes(x=factor(timeID, level = time_order), y=time3, group=subID, col=groupID)) + 
      scale_color_manual(values=wes_palette(n=3, name="GrandBudapest1")) + 
      facet_grid(~groupID) +
      geom_line(aes(y=time3, group=subID)) + 
      geom_line(aes(y=fit3), size=5.5) +
      geom_point(alpha = 0.3) + 
      geom_hline(yintercept=0, linetype="dashed") +
      theme_bw()

Time4
lmm <- lmer(time4 ~ groupID * timeID + (1 | subID), data = MixedANOVA_BraverSeed,
            REML = FALSE)

MixedANOVA_BraverSeed$fit4 <- predict(lmm)
time_order <- c('pre', 'post') 

ggplot(MixedANOVA_BraverSeed, aes(x=factor(timeID, level = time_order), y=time4, group=subID, col=groupID)) + 
      scale_color_manual(values=wes_palette(n=3, name="GrandBudapest1")) + 
      facet_grid(~groupID) +
      geom_line(aes(y=time4, group=subID)) + 
      geom_line(aes(y=fit4), size=5.5) +
      geom_point(alpha = 0.3) + 
      geom_hline(yintercept=0, linetype="dashed") +
      theme_bw()

Time5
library(RColorBrewer)
library(ggeffects)

time_order <- c('pre', 'post') 
MixedANOVA_BraverSeed$timeID = factor(MixedANOVA_BraverSeed$timeID, level = time_order)

lmm <- lmer(time5 ~ groupID * timeID + (1 | subID), data = MixedANOVA_BraverSeed,
            REML = FALSE)

MixedANOVA_BraverSeed$fit5 <- predict(lmm)

ggplot(MixedANOVA_BraverSeed, aes(x=factor(timeID, level = time_order), y=time5, group=subID, col=groupID)) + 
      scale_color_manual(values=wes_palette(n=3, name="GrandBudapest1")) + 
      facet_grid(~groupID) +
      geom_line(aes(y=time5, group=subID)) + 
      geom_line(aes(y=fit5), size=5.5) +
      geom_point(alpha = 0.3) + 
      geom_hline(yintercept=0, linetype="dashed") +
      theme_bw()

#***********************************************************************#
# Ash edits on 09/29/19 to identify individual difference effects: BEGIN
# Reference 1: https://mran.microsoft.com/snapshot/2017-04-27/web/packages/sjPlot/vignettes/sjplmer.html
# Reference 2: https://stats.stackexchange.com/questions/122009/extracting-slopes-for-cases-from-a-mixed-effects-model-lme4
# Reference 3: https://strengejacke.github.io/ggeffects/articles/randomeffects.html
# Reference 4: https://stackoverflow.com/questions/53855738/plotting-random-slopes-from-glmer-model-using-sjplot
#---------------------------------------------------------------#
#                       *METHOD 1*                              #
#---------------------------------------------------------------#

#-----INDIVIDUAL [SUBJECT] PLOTS IN EACH GROUP------
MixedANOVA_BraverSeed_AE <- data.frame(MixedANOVA_BraverSeed[ which(MixedANOVA_BraverSeed$groupID == 'AE'),])
p1 <- ggplot(data = MixedANOVA_BraverSeed_AE, aes(x=factor(timeID, level = time_order), y = time5, group=groupID)) + geom_point() + stat_smooth(method = "lm", se = FALSE) + facet_wrap(~subID) 
p1

#-----INDIVIDUAL [SUBJECT] PLOTS IN EACH GROUP------

coef(lmm)$subID
##         (Intercept) groupIDUAA timeIDpost groupIDUAA:timeIDpost
## sub01   -0.62542612  0.6047954   0.819752             -1.355077
## sub04   -0.51327862  0.6047954   0.819752             -1.355077
## sub05   -0.49366186  0.6047954   0.819752             -1.355077
## sub07   -0.69447305  0.6047954   0.819752             -1.355077
## sub11   -0.81887404  0.6047954   0.819752             -1.355077
## sub12   -0.33372369  0.6047954   0.819752             -1.355077
## sub13   -0.65935840  0.6047954   0.819752             -1.355077
## sub14   -0.51819192  0.6047954   0.819752             -1.355077
## sub16   -0.69031040  0.6047954   0.819752             -1.355077
## sub20   -0.54253327  0.6047954   0.819752             -1.355077
## sub21   -0.52905272  0.6047954   0.819752             -1.355077
## sub22   -0.51622027  0.6047954   0.819752             -1.355077
## sub23   -0.14473628  0.6047954   0.819752             -1.355077
## sub24   -0.36807689  0.6047954   0.819752             -1.355077
## sub25   -0.42297680  0.6047954   0.819752             -1.355077
## sub6001 -0.71843646  0.6047954   0.819752             -1.355077
## sub6002 -0.66586391  0.6047954   0.819752             -1.355077
## sub6004 -0.39245690  0.6047954   0.819752             -1.355077
## sub6005 -0.34082953  0.6047954   0.819752             -1.355077
## sub6006 -0.33611587  0.6047954   0.819752             -1.355077
## sub6009 -0.45283910  0.6047954   0.819752             -1.355077
## sub6011 -0.29202717  0.6047954   0.819752             -1.355077
## sub6014 -0.52447477  0.6047954   0.819752             -1.355077
## sub6015 -0.49034940  0.6047954   0.819752             -1.355077
## sub6016 -0.39629128  0.6047954   0.819752             -1.355077
## sub6017 -0.39781954  0.6047954   0.819752             -1.355077
## sub6018 -0.79930282  0.6047954   0.819752             -1.355077
## sub6019 -0.69824654  0.6047954   0.819752             -1.355077
## sub6020 -0.41604515  0.6047954   0.819752             -1.355077
## sub6021 -0.66777220  0.6047954   0.819752             -1.355077
## sub6022 -0.41425577  0.6047954   0.819752             -1.355077
## sub6023 -0.26661448  0.6047954   0.819752             -1.355077
## sub6024 -0.09176272  0.6047954   0.819752             -1.355077
## sub6025 -0.52596088  0.6047954   0.819752             -1.355077
## sub6027 -0.49273629  0.6047954   0.819752             -1.355077
## sub6028 -0.64176963  0.6047954   0.819752             -1.355077
## sub6029 -0.46655057  0.6047954   0.819752             -1.355077
## sub6030 -0.56837053  0.6047954   0.819752             -1.355077
## sub6032 -0.49909632  0.6047954   0.819752             -1.355077
## sub6033 -0.13252678  0.6047954   0.819752             -1.355077
## sub6036 -0.49540416  0.6047954   0.819752             -1.355077
## sub6038 -0.52608238  0.6047954   0.819752             -1.355077
## sub6039 -0.69273112  0.6047954   0.819752             -1.355077
## sub6041 -0.30851008  0.6047954   0.819752             -1.355077
## sub6042 -0.25305274  0.6047954   0.819752             -1.355077
## sub6044 -0.56731289  0.6047954   0.819752             -1.355077
## sub6047 -0.47075178  0.6047954   0.819752             -1.355077
## sub6049 -0.56466753  0.6047954   0.819752             -1.355077
## sub6051 -0.36565659  0.6047954   0.819752             -1.355077
## sub6052 -0.48114827  0.6047954   0.819752             -1.355077
## sub6054 -0.39898193  0.6047954   0.819752             -1.355077
## sub6058 -0.45586587  0.6047954   0.819752             -1.355077
## sub6059 -0.70363180  0.6047954   0.819752             -1.355077
## sub6062 -0.43940708  0.6047954   0.819752             -1.355077
## sub6063  0.03578612  0.6047954   0.819752             -1.355077
## sub6064 -0.53708652  0.6047954   0.819752             -1.355077
## sub6065 -0.69381302  0.6047954   0.819752             -1.355077
## sub6066  0.02621880  0.6047954   0.819752             -1.355077
## sub6067 -0.37851924  0.6047954   0.819752             -1.355077
## sub6069 -0.39487019  0.6047954   0.819752             -1.355077
## sub6070 -0.59326110  0.6047954   0.819752             -1.355077
## sub6074 -0.36432471  0.6047954   0.819752             -1.355077
## sub6075 -0.47350842  0.6047954   0.819752             -1.355077
## sub6076 -0.46498410  0.6047954   0.819752             -1.355077
## sub6080 -0.20596470  0.6047954   0.819752             -1.355077
## sub6081 -0.51839782  0.6047954   0.819752             -1.355077
## sub6084 -0.34624706  0.6047954   0.819752             -1.355077
## sub6085 -0.49917536  0.6047954   0.819752             -1.355077
## sub6087 -0.11080593  0.6047954   0.819752             -1.355077
## sub6089 -0.25346865  0.6047954   0.819752             -1.355077
## sub6090 -0.53903803  0.6047954   0.819752             -1.355077
## sub6091 -0.67938376  0.6047954   0.819752             -1.355077
## sub6094 -0.70179590  0.6047954   0.819752             -1.355077
## sub6099 -0.57966599  0.6047954   0.819752             -1.355077
## sub6101 -0.29553781  0.6047954   0.819752             -1.355077
## sub6105 -0.40629839  0.6047954   0.819752             -1.355077
## sub6106 -0.43809758  0.6047954   0.819752             -1.355077
## sub6107 -0.39079502  0.6047954   0.819752             -1.355077
## sub6108 -0.91707658  0.6047954   0.819752             -1.355077
## sub6109 -0.97543046  0.6047954   0.819752             -1.355077
## sub6112 -0.47728419  0.6047954   0.819752             -1.355077
## sub6113 -0.57044869  0.6047954   0.819752             -1.355077
## sub6114 -0.43580222  0.6047954   0.819752             -1.355077
## sub6115 -0.71352303  0.6047954   0.819752             -1.355077
## sub6117 -0.29169503  0.6047954   0.819752             -1.355077
## sub6119 -0.21012422  0.6047954   0.819752             -1.355077
## sub6120 -1.28526102  0.6047954   0.819752             -1.355077
## sub6121 -0.57161133  0.6047954   0.819752             -1.355077
## sub6122 -0.39284085  0.6047954   0.819752             -1.355077
## sub6123 -0.39330371  0.6047954   0.819752             -1.355077
## sub6124 -0.74771993  0.6047954   0.819752             -1.355077
## sub6126 -0.84332867  0.6047954   0.819752             -1.355077
## sub6128 -0.31735488  0.6047954   0.819752             -1.355077
## sub6129 -0.38190563  0.6047954   0.819752             -1.355077
## sub6130 -0.48601950  0.6047954   0.819752             -1.355077
## sub6131 -0.44977976  0.6047954   0.819752             -1.355077
## sub6132 -0.32463035  0.6047954   0.819752             -1.355077
## sub6133 -0.08164240  0.6047954   0.819752             -1.355077
## sub6134 -0.46306577  0.6047954   0.819752             -1.355077
## sub6136 -0.39243107  0.6047954   0.819752             -1.355077
## sub6140 -0.62934557  0.6047954   0.819752             -1.355077
## sub6141 -0.45838774  0.6047954   0.819752             -1.355077
## sub6142 -0.68326455  0.6047954   0.819752             -1.355077
## sub6143 -0.58978544  0.6047954   0.819752             -1.355077
## sub6145 -0.30197562  0.6047954   0.819752             -1.355077
## sub6147 -0.71843456  0.6047954   0.819752             -1.355077
## sub6149 -0.26139399  0.6047954   0.819752             -1.355077
## sub6151 -0.30080498  0.6047954   0.819752             -1.355077
## sub6153 -0.42705372  0.6047954   0.819752             -1.355077
## sub6157 -0.13117637  0.6047954   0.819752             -1.355077
## sub6159 -0.44735528  0.6047954   0.819752             -1.355077
## sub6161 -0.39156613  0.6047954   0.819752             -1.355077
## sub6162 -0.02369551  0.6047954   0.819752             -1.355077
## sub6163 -0.71775222  0.6047954   0.819752             -1.355077
## sub6166 -0.75583195  0.6047954   0.819752             -1.355077
## sub6169 -0.51747072  0.6047954   0.819752             -1.355077
## sub6170 -0.52292002  0.6047954   0.819752             -1.355077
## sub6171 -0.30216360  0.6047954   0.819752             -1.355077
## sub6172 -0.47316190  0.6047954   0.819752             -1.355077
## sub6175 -0.24250108  0.6047954   0.819752             -1.355077
## sub6177 -0.17296159  0.6047954   0.819752             -1.355077
## sub6178 -0.19958064  0.6047954   0.819752             -1.355077
## sub6179 -0.40927871  0.6047954   0.819752             -1.355077
## sub6180 -0.26649251  0.6047954   0.819752             -1.355077
## sub6186 -0.69209376  0.6047954   0.819752             -1.355077
## sub6187 -0.40733543  0.6047954   0.819752             -1.355077
## sub6190 -0.46949218  0.6047954   0.819752             -1.355077
## sub6191 -0.23334899  0.6047954   0.819752             -1.355077
## sub6193 -0.54457897  0.6047954   0.819752             -1.355077
## sub6194 -0.32216779  0.6047954   0.819752             -1.355077
## sub6198 -0.48276718  0.6047954   0.819752             -1.355077
## sub6199 -0.53456453  0.6047954   0.819752             -1.355077
## sub6200 -0.76215218  0.6047954   0.819752             -1.355077
## sub6204 -0.53123432  0.6047954   0.819752             -1.355077
## sub6207 -0.67966706  0.6047954   0.819752             -1.355077
## sub6209 -0.50693338  0.6047954   0.819752             -1.355077
## sub6214 -0.23179001  0.6047954   0.819752             -1.355077
## sub6215 -0.44177702  0.6047954   0.819752             -1.355077
## sub6216 -0.74299724  0.6047954   0.819752             -1.355077
## sub6217 -0.51646061  0.6047954   0.819752             -1.355077
## sub6218 -0.41793265  0.6047954   0.819752             -1.355077
## sub6219 -0.33991475  0.6047954   0.819752             -1.355077
ranef(lmm)$subID
##           (Intercept)
## sub01   -0.1563452148
## sub04   -0.0441977098
## sub05   -0.0245809485
## sub07   -0.2253921382
## sub11   -0.3497931266
## sub12    0.1353572202
## sub13   -0.1902774859
## sub14   -0.0491110138
## sub16   -0.2212294861
## sub20   -0.0734523610
## sub21   -0.0599718121
## sub22   -0.0471393616
## sub23    0.3243446327
## sub24    0.1010040169
## sub25    0.0461041116
## sub6001 -0.2493555472
## sub6002 -0.1967829984
## sub6004  0.0766240129
## sub6005  0.1282513825
## sub6006  0.1329650383
## sub6009  0.0162418082
## sub6011  0.1770537394
## sub6014 -0.0553938572
## sub6015 -0.0212684944
## sub6016  0.0727896304
## sub6017  0.0712613741
## sub6018 -0.3302219087
## sub6019 -0.2291656280
## sub6020  0.0530357624
## sub6021 -0.1986912906
## sub6022  0.0548251381
## sub6023  0.2024664266
## sub6024  0.3773181930
## sub6025 -0.0568799726
## sub6027 -0.0236553753
## sub6028 -0.1726887243
## sub6029  0.0025303371
## sub6030 -0.0992896165
## sub6032 -0.0300154135
## sub6033  0.3365541304
## sub6036 -0.0263232488
## sub6038 -0.0570014674
## sub6039 -0.2236502111
## sub6041  0.1605708322
## sub6042  0.2160281709
## sub6044 -0.0982319773
## sub6047 -0.0016708673
## sub6049 -0.0955866198
## sub6051  0.1034243181
## sub6052 -0.0120673572
## sub6054  0.0700989827
## sub6058  0.0132150440
## sub6059 -0.2345508851
## sub6062  0.0296738258
## sub6063  0.5048670302
## sub6064 -0.0680056146
## sub6065 -0.2247321114
## sub6066  0.4952997121
## sub6067  0.0905616701
## sub6069  0.0742107245
## sub6070 -0.1241801858
## sub6074  0.1047562024
## sub6075 -0.0044275127
## sub6076  0.0040968079
## sub6080  0.2631162070
## sub6081 -0.0493169075
## sub6084  0.1228338497
## sub6085 -0.0300944514
## sub6087  0.3582749780
## sub6089  0.2156122582
## sub6090 -0.0699571185
## sub6091 -0.2103028452
## sub6094 -0.2327149908
## sub6099 -0.1105850826
## sub6101  0.1735430996
## sub6105  0.0627825177
## sub6106  0.0309833260
## sub6107  0.0782858945
## sub6108 -0.4479956727
## sub6109 -0.5063495477
## sub6112 -0.0082032803
## sub6113 -0.1013677806
## sub6114  0.0332786853
## sub6115 -0.2444421156
## sub6117  0.1773858757
## sub6119  0.2589566920
## sub6120 -0.8161801148
## sub6121 -0.1025304247
## sub6122  0.0762400599
## sub6123  0.0757772046
## sub6124 -0.2786390177
## sub6126 -0.3742477552
## sub6128  0.1517260291
## sub6129  0.0871752840
## sub6130 -0.0169385927
## sub6131  0.0193011547
## sub6132  0.1444505585
## sub6133  0.3874385147
## sub6134  0.0060151364
## sub6136  0.0766498441
## sub6140 -0.1602646613
## sub6141  0.0106931681
## sub6142 -0.2141836362
## sub6143 -0.1207045290
## sub6145  0.1671052939
## sub6147 -0.2493536518
## sub6149  0.2076869208
## sub6151  0.1682759255
## sub6153  0.0420271931
## sub6157  0.3379045448
## sub6159  0.0217256259
## sub6161  0.0775147849
## sub6162  0.4453853998
## sub6163 -0.2486713099
## sub6166 -0.2867510429
## sub6169 -0.0483898070
## sub6170 -0.0538391096
## sub6171  0.1669173069
## sub6172 -0.0040809874
## sub6175  0.2265798304
## sub6177  0.2961193162
## sub6178  0.2695002738
## sub6179  0.0598021998
## sub6180  0.2025884042
## sub6186 -0.2230128532
## sub6187  0.0617454843
## sub6190 -0.0004112671
## sub6191  0.2357319215
## sub6193 -0.0754980600
## sub6194  0.1469131178
## sub6198 -0.0136862669
## sub6199 -0.0654836184
## sub6200 -0.2930712701
## sub6204 -0.0621534108
## sub6207 -0.2105861527
## sub6209 -0.0378524671
## sub6214  0.2372908959
## sub6215  0.0273038881
## sub6216 -0.2739163272
## sub6217 -0.0473796976
## sub6218  0.0511482629
## sub6219  0.1291661642
pp <- ggpredict(lmm, terms=c("timeID","subID"), type="re")
plot(pp, colors = colorRampPalette(brewer.pal(11,"Spectral"))(142), connect.lines=TRUE)

pp
## 
## # Predicted values of time5
## # x = timeID
## 
## # subID = sub01
##     x predicted
##   pre    -0.625
##  post     0.194
## 
## # subID = sub04
##     x predicted
##   pre    -0.513
##  post     0.306
## 
## # subID = sub05
##     x predicted
##   pre    -0.494
##  post     0.326
## 
## # subID = sub07
##     x predicted
##   pre    -0.694
##  post     0.125
## 
## # subID = sub11
##     x predicted
##   pre    -0.819
##  post     0.001
## 
## # subID = sub12
##     x predicted
##   pre    -0.334
##  post     0.486
## 
## # subID = sub13
##     x predicted
##   pre    -0.659
##  post     0.160
## 
## # subID = sub14
##     x predicted
##   pre    -0.518
##  post     0.302
## 
## # subID = sub16
##     x predicted
##   pre    -0.690
##  post     0.129
## 
## # subID = sub20
##     x predicted
##   pre    -0.543
##  post     0.277
## 
## # subID = sub21
##     x predicted
##   pre    -0.529
##  post     0.291
## 
## # subID = sub22
##     x predicted
##   pre    -0.516
##  post     0.304
## 
## # subID = sub23
##     x predicted
##   pre    -0.145
##  post     0.675
## 
## # subID = sub24
##     x predicted
##   pre    -0.368
##  post     0.452
## 
## # subID = sub25
##     x predicted
##   pre    -0.423
##  post     0.397
## 
## # subID = sub6001
##     x predicted
##   pre    -0.718
##  post     0.101
## 
## # subID = sub6002
##     x predicted
##   pre    -0.666
##  post     0.154
## 
## # subID = sub6004
##     x predicted
##   pre    -0.392
##  post     0.427
## 
## # subID = sub6005
##     x predicted
##   pre    -0.341
##  post     0.479
## 
## # subID = sub6006
##     x predicted
##   pre    -0.336
##  post     0.484
## 
## # subID = sub6009
##     x predicted
##   pre    -0.453
##  post     0.367
## 
## # subID = sub6011
##     x predicted
##   pre    -0.292
##  post     0.528
## 
## # subID = sub6014
##     x predicted
##   pre    -0.524
##  post     0.295
## 
## # subID = sub6015
##     x predicted
##   pre    -0.490
##  post     0.329
## 
## # subID = sub6016
##     x predicted
##   pre    -0.396
##  post     0.423
## 
## # subID = sub6017
##     x predicted
##   pre    -0.398
##  post     0.422
## 
## # subID = sub6018
##     x predicted
##   pre    -0.799
##  post     0.020
## 
## # subID = sub6019
##     x predicted
##   pre    -0.698
##  post     0.122
## 
## # subID = sub6020
##     x predicted
##   pre    -0.416
##  post     0.404
## 
## # subID = sub6021
##     x predicted
##   pre    -0.668
##  post     0.152
## 
## # subID = sub6022
##     x predicted
##   pre    -0.414
##  post     0.405
## 
## # subID = sub6023
##     x predicted
##   pre    -0.267
##  post     0.553
## 
## # subID = sub6024
##     x predicted
##   pre    -0.092
##  post     0.728
## 
## # subID = sub6025
##     x predicted
##   pre    -0.526
##  post     0.294
## 
## # subID = sub6027
##     x predicted
##   pre    -0.493
##  post     0.327
## 
## # subID = sub6028
##     x predicted
##   pre    -0.642
##  post     0.178
## 
## # subID = sub6029
##     x predicted
##   pre    -0.467
##  post     0.353
## 
## # subID = sub6030
##     x predicted
##   pre    -0.568
##  post     0.251
## 
## # subID = sub6032
##     x predicted
##   pre    -0.499
##  post     0.321
## 
## # subID = sub6033
##     x predicted
##   pre    -0.133
##  post     0.687
## 
## # subID = sub6036
##     x predicted
##   pre    -0.495
##  post     0.324
## 
## # subID = sub6038
##     x predicted
##   pre    -0.526
##  post     0.294
## 
## # subID = sub6039
##     x predicted
##   pre    -0.693
##  post     0.127
## 
## # subID = sub6041
##     x predicted
##   pre    -0.309
##  post     0.511
## 
## # subID = sub6042
##     x predicted
##   pre    -0.253
##  post     0.567
## 
## # subID = sub6044
##     x predicted
##   pre    -0.567
##  post     0.252
## 
## # subID = sub6047
##     x predicted
##   pre    -0.471
##  post     0.349
## 
## # subID = sub6049
##     x predicted
##   pre    -0.565
##  post     0.255
## 
## # subID = sub6051
##     x predicted
##   pre    -0.366
##  post     0.454
## 
## # subID = sub6052
##     x predicted
##   pre    -0.481
##  post     0.339
## 
## # subID = sub6054
##     x predicted
##   pre    -0.399
##  post     0.421
## 
## # subID = sub6058
##     x predicted
##   pre    -0.456
##  post     0.364
## 
## # subID = sub6059
##     x predicted
##   pre    -0.704
##  post     0.116
## 
## # subID = sub6062
##     x predicted
##   pre    -0.439
##  post     0.380
## 
## # subID = sub6063
##     x predicted
##   pre     0.036
##  post     0.856
## 
## # subID = sub6064
##     x predicted
##   pre    -0.537
##  post     0.283
## 
## # subID = sub6065
##     x predicted
##   pre    -0.694
##  post     0.126
## 
## # subID = sub6066
##     x predicted
##   pre     0.026
##  post     0.846
## 
## # subID = sub6067
##     x predicted
##   pre    -0.379
##  post     0.441
## 
## # subID = sub6069
##     x predicted
##   pre    -0.395
##  post     0.425
## 
## # subID = sub6070
##     x predicted
##   pre    -0.593
##  post     0.226
## 
## # subID = sub6074
##     x predicted
##   pre    -0.364
##  post     0.455
## 
## # subID = sub6075
##     x predicted
##   pre    -0.474
##  post     0.346
## 
## # subID = sub6076
##     x predicted
##   pre    -0.465
##  post     0.355
## 
## # subID = sub6080
##     x predicted
##   pre    -0.206
##  post     0.614
## 
## # subID = sub6081
##     x predicted
##   pre    -0.518
##  post     0.301
## 
## # subID = sub6084
##     x predicted
##   pre    -0.346
##  post     0.474
## 
## # subID = sub6085
##     x predicted
##   pre    -0.499
##  post     0.321
## 
## # subID = sub6087
##     x predicted
##   pre    -0.111
##  post     0.709
## 
## # subID = sub6089
##     x predicted
##   pre    -0.253
##  post     0.566
## 
## # subID = sub6090
##     x predicted
##   pre    -0.539
##  post     0.281
## 
## # subID = sub6091
##     x predicted
##   pre    -0.679
##  post     0.140
## 
## # subID = sub6094
##     x predicted
##   pre    -0.702
##  post     0.118
## 
## # subID = sub6099
##     x predicted
##   pre     -0.58
##  post      0.24
## 
## # subID = sub6101
##     x predicted
##   pre    -0.296
##  post     0.524
## 
## # subID = sub6105
##     x predicted
##   pre    -0.406
##  post     0.413
## 
## # subID = sub6106
##     x predicted
##   pre    -0.438
##  post     0.382
## 
## # subID = sub6107
##     x predicted
##   pre    -0.391
##  post     0.429
## 
## # subID = sub6108
##     x predicted
##   pre    -0.917
##  post    -0.097
## 
## # subID = sub6109
##     x predicted
##   pre    -0.975
##  post    -0.156
## 
## # subID = sub6112
##     x predicted
##   pre    -0.477
##  post     0.342
## 
## # subID = sub6113
##     x predicted
##   pre    -0.570
##  post     0.249
## 
## # subID = sub6114
##     x predicted
##   pre    -0.436
##  post     0.384
## 
## # subID = sub6115
##     x predicted
##   pre    -0.714
##  post     0.106
## 
## # subID = sub6117
##     x predicted
##   pre    -0.292
##  post     0.528
## 
## # subID = sub6119
##     x predicted
##   pre     -0.21
##  post      0.61
## 
## # subID = sub6120
##     x predicted
##   pre    -1.285
##  post    -0.466
## 
## # subID = sub6121
##     x predicted
##   pre    -0.572
##  post     0.248
## 
## # subID = sub6122
##     x predicted
##   pre    -0.393
##  post     0.427
## 
## # subID = sub6123
##     x predicted
##   pre    -0.393
##  post     0.426
## 
## # subID = sub6124
##     x predicted
##   pre    -0.748
##  post     0.072
## 
## # subID = sub6126
##     x predicted
##   pre    -0.843
##  post    -0.024
## 
## # subID = sub6128
##     x predicted
##   pre    -0.317
##  post     0.502
## 
## # subID = sub6129
##     x predicted
##   pre    -0.382
##  post     0.438
## 
## # subID = sub6130
##     x predicted
##   pre    -0.486
##  post     0.334
## 
## # subID = sub6131
##     x predicted
##   pre     -0.45
##  post      0.37
## 
## # subID = sub6132
##     x predicted
##   pre    -0.325
##  post     0.495
## 
## # subID = sub6133
##     x predicted
##   pre    -0.082
##  post     0.738
## 
## # subID = sub6134
##     x predicted
##   pre    -0.463
##  post     0.357
## 
## # subID = sub6136
##     x predicted
##   pre    -0.392
##  post     0.427
## 
## # subID = sub6140
##     x predicted
##   pre    -0.629
##  post     0.190
## 
## # subID = sub6141
##     x predicted
##   pre    -0.458
##  post     0.361
## 
## # subID = sub6142
##     x predicted
##   pre    -0.683
##  post     0.136
## 
## # subID = sub6143
##     x predicted
##   pre     -0.59
##  post      0.23
## 
## # subID = sub6145
##     x predicted
##   pre    -0.302
##  post     0.518
## 
## # subID = sub6147
##     x predicted
##   pre    -0.718
##  post     0.101
## 
## # subID = sub6149
##     x predicted
##   pre    -0.261
##  post     0.558
## 
## # subID = sub6151
##     x predicted
##   pre    -0.301
##  post     0.519
## 
## # subID = sub6153
##     x predicted
##   pre    -0.427
##  post     0.393
## 
## # subID = sub6157
##     x predicted
##   pre    -0.131
##  post     0.689
## 
## # subID = sub6159
##     x predicted
##   pre    -0.447
##  post     0.372
## 
## # subID = sub6161
##     x predicted
##   pre    -0.392
##  post     0.428
## 
## # subID = sub6162
##     x predicted
##   pre    -0.024
##  post     0.796
## 
## # subID = sub6163
##     x predicted
##   pre    -0.718
##  post     0.102
## 
## # subID = sub6166
##     x predicted
##   pre    -0.756
##  post     0.064
## 
## # subID = sub6169
##     x predicted
##   pre    -0.517
##  post     0.302
## 
## # subID = sub6170
##     x predicted
##   pre    -0.523
##  post     0.297
## 
## # subID = sub6171
##     x predicted
##   pre    -0.302
##  post     0.518
## 
## # subID = sub6172
##     x predicted
##   pre    -0.473
##  post     0.347
## 
## # subID = sub6175
##     x predicted
##   pre    -0.243
##  post     0.577
## 
## # subID = sub6177
##     x predicted
##   pre    -0.173
##  post     0.647
## 
## # subID = sub6178
##     x predicted
##   pre     -0.20
##  post      0.62
## 
## # subID = sub6179
##     x predicted
##   pre    -0.409
##  post     0.410
## 
## # subID = sub6180
##     x predicted
##   pre    -0.266
##  post     0.553
## 
## # subID = sub6186
##     x predicted
##   pre    -0.692
##  post     0.128
## 
## # subID = sub6187
##     x predicted
##   pre    -0.407
##  post     0.412
## 
## # subID = sub6190
##     x predicted
##   pre    -0.469
##  post     0.350
## 
## # subID = sub6191
##     x predicted
##   pre    -0.233
##  post     0.586
## 
## # subID = sub6193
##     x predicted
##   pre    -0.545
##  post     0.275
## 
## # subID = sub6194
##     x predicted
##   pre    -0.322
##  post     0.498
## 
## # subID = sub6198
##     x predicted
##   pre    -0.483
##  post     0.337
## 
## # subID = sub6199
##     x predicted
##   pre    -0.535
##  post     0.285
## 
## # subID = sub6200
##     x predicted
##   pre    -0.762
##  post     0.058
## 
## # subID = sub6204
##     x predicted
##   pre    -0.531
##  post     0.289
## 
## # subID = sub6207
##     x predicted
##   pre     -0.68
##  post      0.14
## 
## # subID = sub6209
##     x predicted
##   pre    -0.507
##  post     0.313
## 
## # subID = sub6214
##     x predicted
##   pre    -0.232
##  post     0.588
## 
## # subID = sub6215
##     x predicted
##   pre    -0.442
##  post     0.378
## 
## # subID = sub6216
##     x predicted
##   pre    -0.743
##  post     0.077
## 
## # subID = sub6217
##     x predicted
##   pre    -0.516
##  post     0.303
## 
## # subID = sub6218
##     x predicted
##   pre    -0.418
##  post     0.402
## 
## # subID = sub6219
##     x predicted
##   pre     -0.34
##  post      0.48
## 
## Adjusted for:
## * groupID = AE
#---------------------------------------------------------------#
#                       *METHOD 2*                              #
#---------------------------------------------------------------#

#-----INTERCEPT PLOT------
library(sjPlot)
library(sjmisc)
set_theme( 
          geom.label.size = 2, 
          axis.textsize = .9, 
          axis.title.size = .9)

plot_model(lmm, 
           type="re",
           facet.grid=TRUE) #sort.est="(Intercept)"

           ## too much hodge-podge; evaluate each groupID separately
#-----INTERCEPT PLOT------

#-----SCATTER PLOT (without lines)------

me <- ggpredict(lmm, 
                c("groupID","subID","timeID"), 
                type = "re") 
plot(me,colors = colorRampPalette(brewer.pal(11,"Spectral"))(142))

#-----SCATTER PLOT (without lines)------


# Ash edits on 09/29/19 to identify individual difference effects: END
#***********************************************************************#
Time6
lmm <- lmer(time6 ~ groupID * timeID + (1 | subID), data = MixedANOVA_BraverSeed,
            REML = FALSE)

MixedANOVA_BraverSeed$fit6 <- predict(lmm)
time_order <- c('pre', 'post') 

ggplot(MixedANOVA_BraverSeed, aes(x=factor(timeID, level = time_order), y=time6, group=subID, col=groupID)) + 
      scale_color_manual(values=wes_palette(n=3, name="GrandBudapest1")) + 
      facet_grid(~groupID) +
      geom_line(aes(y=time6, group=subID)) + 
      geom_line(aes(y=fit6), size=5.5) +
      geom_point(alpha = 0.3) + 
      geom_hline(yintercept=0, linetype="dashed") +
      theme_bw()

SummaryTable_SignificantInteractions

Region Time Point Cue(C) or Probe(P) Post-Pre Trend: AE>UAA (AE^) or UAA>AE (UAA^) Expected Direction?: Y/N
BA6_subFrontal_R 3 C AE^ Y
BA6_subFrontal_R 4 C AE^ Y
BA6_subFrontal_R 5 P AE^ N
BA6_subFrontal_R 6 P AE^ N