# Modelling binomial outcome in repeated measures design using glmer

I have a complex dataset for a repeated measures design.

Each participant (N=53) saw a total of 72 images that varied according to three different properties (2 categorical and 1 ordinal independent variables). The task was to make an estimate about an object depicted in the image on a scale from 1 to 6. The estimate was quantified as accurate if it was +1 or -1 of the correct number of the scale. Accuracy was created as binomial variable which terms are defined a follows: 1= within +1 or -1 unit from the correct response; and 0= more than +1 or -1 away from the correct response.

I would like to predict the accuracy (binomial dependent variable) of participants' estimations, based on the three manipulated image properties (independent variables) and on participants' subjective ratings (treated as independent variable: e.g. computer expertise), taking into account participant identity, image identity and random order as nested random factor of the repeated measures design.

I created a model using glm

> model1 <- glm(accurate ~ NP + fov + secondhalf + Training +
> randomcount +
>               + DurationSec + ScreenSize + AttentionCheck
>               + CompExp1to4 + PalyingFreq1to5 + Knowledge3D1to4
>               + Gender_0fem1male + Age +
>               + fov:NP + AttentionCheck:NP + ScreenSize:fov
>               + fov:NP:ScreenSize,
>               family = binomial (link = probit),
>               data = Dfnew)


However it does not take into account nested random factors! So I am trying to use glmer, but I keep receiving the Warning message below:

>  model2c <- glmer(accurate ~ NP + fov + Gender_0fem1male + CompExp1to4
>
>                  + (PID|distimage), family=binomial,
>                  data = Dfnew)


Now I receive this warning message:

> Warning messages: 1: In checkConv(attr(opt, "derivs"), opt$$par, ctrl = > control$$checkConv,  :   Model failed to converge with max|grad| =
> 0.0341347 (tol = 0.001, component 1) 2: In checkConv(attr(opt, "derivs"), opt$$par, ctrl = control$$checkConv,  :   Model is nearly
> unidentifiable: very large eigenvalue
>  - Rescale variables?;Model is nearly unidentifiable: large eigenvalue ratio
>  - Rescale variables?


Any suggestion about how to improve the model or to address the warning message would be much appreciated!

Data structure:

'data.frame':   3816 obs. of  29 variables:
$$X : int 1 2 3 4 5 6 7 8 9 10 ...$$ PID               : int  1 2 3 4 5 6 7 8 9 10 ...
$$DurationSec : int 467 992 821 708 1110 704 903 665 733 886 ...$$ Browser           : Factor w/ 4 levels "Chrome","Edge",..: 1 1 1 1 1 1 1 1 1 1 ...
$$Resolution : Factor w/ 11 levels "1215x684","1280x720",..: 6 11 2 4 11 4 11 9 4 11 ...$$ Device1comp0laptop: int  1 1 0 1 1 0 1 1 0 1 ...
$$ScreenSize : int 15 27 15 17 15 29 21 17 15 21 ...$$ Gender_0fem1male  : int  0 0 0 0 0 0 0 0 0 0 ...
$$Age : int 19 18 18 18 18 18 18 18 18 18 ...$$ AttentionCheck    : int  3 3 3 3 2 0 2 3 3 2 ...
$$CompExp1to4 : int 5 4 5 4 5 5 4 5 5 5 ...$$ PalyingFreq1to5   : int  3 5 3 4 1 2 5 3 2 4 ...
$$Knowledge3D1to4 : int 2 2 2 2 1 1 2 2 5 2 ...$$ TrainingLP        : int  1 1 0 0 0 1 1 0 0 1 ...
$$TrainingNP : int 0 0 1 1 1 0 0 1 1 0 ...$$ imageCODE         : Factor w/ 72 levels "n1_5_100LP_P",..: 1 1 1 1 1 1 1 1 1 1 ...
$$chosendistance : int 4 4 4 4 3 4 4 4 4 4 ...$$ orderCODE         : Factor w/ 72 levels "Order_n1_5_100LP_P",..: 1 1 1 1 1 1 1 1 1 1 ...
$$randomcount : int 33 51 29 33 52 63 10 37 13 47 ...$$ lpornp            : Factor w/ 2 levels "LP","NP": 1 1 1 1 1 1 1 1 1 1 ...
$$fov : int 100 100 100 100 100 100 100 100 100 100 ...$$ distimage         : int  5 5 5 5 5 5 5 5 5 5 ...
$$rightwrong : int 0 0 0 0 0 0 0 0 0 0 ...$$ difference        : int  1 1 1 1 2 1 1 1 1 1 ...
$$accurate : int 1 1 1 1 0 1 1 1 1 1 ...$$ NP                : int  0 0 0 0 0 0 0 0 0 0 ...
$$LP : int 1 1 1 1 1 1 1 1 1 1 ...$$ secondhalf        : int  0 1 0 0 1 1 0 1 0 1 ...
\$ Training          : Factor w/ 2 levels "LP","NP": 1 1 2 2 2 1 1 2 2 1 ..


The warning messages says the model is not converging and one possible solution is to scale the numeric variables (subtract mean divide by standard deviation).

If the model still fails to converge then I would start with a simpler model and build up to see where it fails. The model currently specified may be too complicated given the random effect structure especially with only 53 subjects.

• It is sill recommending to scale the variables, did you try this? Also, are the variables continuous are should they be treated as factors? (in which case you don't need to rescale them but you do need to specify they are factors).
– Glen
Mar 6, 2019 at 16:05
• I don't think your random effect is specified correctly. For one, you're not specifying any nested effects. Maybe start with two random interecepts: (1|PID)+(1| distimage). I don't know the design/data well enough to know if you need the nested structure, probably not if every person is seeing the same images.
– Glen
Mar 6, 2019 at 16:11
• Hi @Glen, thank you very much for your feedback: it is really useful. So my outcome variable is a binomial variable. I simplified the model so that now it is just: glmer(rightwrong ~ NP + fov + NP:fov + (1| PID) + (1 | distimage), family=binomial, data = Dfnew, na.action = na.omit, control = glmerControl(optimizer = "bobyqa"), nAGQ = 0) Where: NP is a binomial var and fov is an ordinal var (both coded as factors). Using the optimiser seems to solve that problem. Mar 8, 2019 at 11:55
• However, something odd happens when I specify the contrasts for the three levels of the ordinal var fov and ask for the summary of my model: the Intercept becomes significant. I know this can happen with binomial predictors, but I am struggling to interpret this result... Mar 8, 2019 at 12:00
• Fixed effects: Estimate Std. Error z value Pr(>|z|) (Intercept) -1.6609 0.3102 -5.355 8.57e-08 *** lpornpNP 1.6620 0.1375 12.086 < 2e-16 *** fovFov140vs100 1.2494 0.1378 9.066 < 2e-16 *** fovFov140vs120 1.7123 0.1376 12.444 < 2e-16 *** lpornpNP:fovFov140vs100 -1.3141 0.1827 -7.194 6.31e-13 *** lpornpNP:fovFov140vs120 -1.8005 0.1826 -9.861 < 2e-16 *** Mar 8, 2019 at 12:00