Eryn is going to explain what we talked about and the problem she came in with here:

When running basic growth models (not even adding any covariates yet) my models are not converging past the random intercept fixed linear growth model (i.e., the random intercept and linear growth model and the random linear fixed quad models are not converging, even when increasing iteration)

OK Pamela now:

Whattup, Steve! Eryn and I after concensus, realized that we didn’t really know how to address convergence issues beyond hiking up the iterations. Even when Eryn did that, nothing converged. Also, we thought together that convergence issues in our super limited experience usually occurred when data is super f’d up, or when you are overtaxing your model. Since convergence issues occurred super early on in her model, we were confused and thinking it was probably not the latter reason causing the convergence failure. So, after scratcing our heads for a few mins about what to do next w/o you, we wanted to graph stuff to look at the individual growth patterns to see if that gave us any insight into wtf was going on…

I couldn’t stop myself so we did shit in R, because why not? #sorrynotsorry

Really, I just wanted to graph the individual growth lines and look at it, but first we had to make sure our stuff was correct in R and similar to what we found in SPSS, and it kind of went wild from there, BUT I think you won’t be displeased…

—————————————-

OK Steve, we are loading packages here

library(lme4)
## Loading required package: Matrix
library(Matrix)
library(ggplot2)
library(RCurl)
## Loading required package: bitops

OK again, Steve, we are uploading data now!

data <- read.csv(text=getURL("https://raw.githubusercontent.com/pjrakhshan/ErynDiss/master/LongData.csv?token=AQ92QVZ7YR-7AdnETwCSYQxOHrEDvh9Mks5cCGybwA%3D%3D"), header = T)

We did some data checking here, making sure the data we uploaded was correct and similar to her SPSS data (it was really clean too BTW!– and trust us – it looked OK!

OK At this point I (Pamela) wasn’t sure that I knew what I was really doing in R, so we checked our models in R against Eryn’s correct models in SPSS

First model, fixed + random intercept of AQ
model1 <- lmer(AQ ~ (1|PID), data = data, )
summary(model1)
## Linear mixed model fit by REML ['lmerMod']
## Formula: AQ ~ (1 | PID)
##    Data: data
## 
## REML criterion at convergence: 295.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.2830 -0.4431  0.0590  0.4873  2.6631 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  PID      (Intercept) 0.13806  0.3716  
##  Residual             0.06819  0.2611  
## Number of obs: 349, groups:  PID, 128
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  2.79028    0.03578   77.97

This one was correct and/or similar to Eryn’s SPSS syntax findings! Huzzah!!

Fixed + random effects of intercept, fixed effect of growth
model2 <- lmer(AQ ~ TimeCent + (1|PID), data = data, )
summary(model2)
## Linear mixed model fit by REML ['lmerMod']
## Formula: AQ ~ TimeCent + (1 | PID)
##    Data: data
## 
## REML criterion at convergence: 306.6
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.2483 -0.4168  0.0619  0.4984  2.6001 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  PID      (Intercept) 0.13836  0.3720  
##  Residual             0.06824  0.2612  
## Number of obs: 349, groups:  PID, 128
## 
## Fixed effects:
##              Estimate Std. Error t value
## (Intercept) 2.7847761  0.0365302  76.232
## TimeCent    0.0007935  0.0010336   0.768
## 
## Correlation of Fixed Effects:
##          (Intr)
## TimeCent -0.196

So was this model! We figured at this point we kind of knew what we were doing recreating it in R. I know, learning to drive & sandwich eating etc, but still…

So, we tested the model that didn’t converge here (adding in random effect of time):

model3 <- lmer(AQ ~ TimeCent + (1+ TimeCent|PID), data = data)
## singular fit
summary(model3)
## Linear mixed model fit by REML ['lmerMod']
## Formula: AQ ~ TimeCent + (1 + TimeCent | PID)
##    Data: data
## 
## REML criterion at convergence: 304.9
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.2181 -0.4147  0.0601  0.4853  2.7965 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev. Corr 
##  PID      (Intercept) 1.463e-01 0.382529      
##           TimeCent    2.112e-06 0.001453 -1.00
##  Residual             6.761e-02 0.260014      
## Number of obs: 349, groups:  PID, 128
## 
## Fixed effects:
##              Estimate Std. Error t value
## (Intercept) 2.7845266  0.0373419  74.568
## TimeCent    0.0007424  0.0010277   0.722
## 
## Correlation of Fixed Effects:
##          (Intr)
## TimeCent -0.305
## convergence code: 0
## singular fit

OK same result as Eryn got in SPSS, and same issue with non-convergence here. So, we used google (guide here:https://cran.r-project.org/web/packages/lme4/lme4.pdf look on page 17) to figure out how to run diagnostics, and we found out we should test two things: 1) test the singularity and, 2) look at the Hessian values

So the two models that ran seem like they are NOT singular, and the model that crashed IS, which means the variance (or covariance?) for our random effect (we thik it is the covariance between PID and TimeCent) is 0.

if (isLMM(model3)) {
  pars <- getME(model3,"theta")
} else {
  ## GLMM: requires both random and fixed parameters
  pars <- getME(model3, c("theta","fixef"))
}
if (require("numDeriv")) {
  cat("hess:\n"); print(hess <- hessian(devfun, unlist(pars)))
  cat("grad:\n"); print(grad <- grad(devfun, unlist(pars)))
  cat("scaled gradient:\n")
  print(scgrad <- solve(chol(hess), grad))
}
## Loading required package: numDeriv
## Warning in library(package, lib.loc = lib.loc, character.only = TRUE,
## logical.return = TRUE, : there is no package called 'numDeriv'
## compare with internal calculations:
model3@optinfo$derivs
## $gradient
## [1] -0.0001197395  0.0034033982  0.0012154229
## 
## $Hessian
##              [,1]         [,2]        [,3]
## [1,]  113.5914993 1.173118e+03  -0.1821432
## [2,] 1173.1182241 1.207399e+05   3.7446861
## [3,]   -0.1821432 3.744686e+00 320.2611923

As you can see from the matrix values, what we think is the covariance (2,2) in this matrix is super close to zero, which is a no no and a problem. Google/the thing we looked at re: Hessian values (https://www.theanalysisfactor.com/wacky-hessian-matrix/) told us the diagonals should not b 0!

At this point we finally got to doing the thing we got into R for in the first place– creating a nice graph of the individaul growth to see what was going on:

##plot##

base.plot <- ggplot(data, aes(x = WAVE, y = AQ, group = PID))
base.plot + geom_line()

OK Cool. We think at this point that the convergence issue has to do with the covariance between TimeCent and ID, which is super close to zero and therefore causing the issue. 0 clue if this is really true, but google, our Singularity tests and the Hessien values seem to point in that direction. Does this mean Eryn’s future models should not be run at all? OR does it mean that we should just now no longer estimate covariance between TimeCent and ID, since its 0 and makes shit crash? Merp _()_/

You are the MLM Master, so we really need to set an appointment with you to figure out next steps.