1
$\begingroup$

I feel this is related to r glmer warnings: model fails to converge & model is nearly unidentifiable, and I think that the reason why the model fit fails (?) is that I have too rare events(?). Sadly, my understanding of the topic is not quite at a level where I would know how to deal with that. I admit the solutions in the linked thread answering the related question are a bit over my level and I am also not sure if they are appropriate for my problem. I don't think I have multicollinearity, but I simply think that I have to few TRUE events (see the table in below reprex code).

I have a binary outcome variable (TRUE/FALSE) - this is an event that happens or not when starting a therapy in an individual. There are repeated measures per individual, (more than one therapy start).

I therefore believe that I need to fit a logistic regression with mixed effect, and I thought lme4::glmer would be my friend.

However - I have this warning. I would highly appreciate your help what I can do to deal with this problem. Thanks many times.

table_switch <- table(df$independ, df$switch)

# I feel this is because of rare events (switch == TRUE)
table_switch
#>    
#>     FALSE TRUE
#>   x   303    3
#>   y   205   16
#>   z   107    5

switch_mod <- lme4::glmer(switch ~ independ + (1 | ID), data = df, family = binomial) 
#> Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
#> Model failed to converge with max|grad| = 0.0157848 (tol = 0.002, component 1)

summary(switch_mod)
#> Generalized linear mixed model fit by maximum likelihood (Laplace
#>   Approximation) [glmerMod]
#>  Family: binomial  ( logit )
#> Formula: switch ~ independ + (1 | ID)
#>    Data: df
#> 
#>      AIC      BIC   logLik deviance df.resid 
#>    153.5    171.4    -72.8    145.5      635 
#> 
#> Scaled residuals: 
#>     Min      1Q  Median      3Q     Max 
#> -3.4045 -0.0099 -0.0018 -0.0002 16.4121 
#> 
#> Random effects:
#>  Groups Name        Variance Std.Dev.
#>  ID     (Intercept) 180.5    13.43   
#> Number of obs: 639, groups:  ID, 451
#> 
#> Fixed effects:
#>               Estimate Std. Error z value Pr(>|z|)    
#> (Intercept) -17.260528   0.004476   -3856   <2e-16 ***
#> independy     8.046245   0.004476    1798   <2e-16 ***
#> independz     4.634270   0.004476    1035   <2e-16 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Correlation of Fixed Effects:
#>           (Intr) indpndy
#> independy 0.000         
#> independz 0.000  0.000  
#> optimizer (Nelder_Mead) convergence code: 0 (OK)
#> Model failed to converge with max|grad| = 0.0157848 (tol = 0.002, component 1)

data

df <-
  structure(list(ID = c(
    1L, 2L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L,
    6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
    19L, 19L, 20L, 20L, 21L, 21L, 22L, 23L, 23L, 24L, 25L, 26L, 27L,
    27L, 28L, 29L, 30L, 30L, 31L, 31L, 32L, 33L, 33L, 33L, 34L, 35L,
    36L, 36L, 37L, 38L, 39L, 40L, 41L, 41L, 41L, 42L, 42L, 43L, 44L,
    44L, 44L, 45L, 46L, 47L, 48L, 49L, 49L, 50L, 51L, 52L, 53L, 54L,
    55L, 56L, 57L, 57L, 58L, 59L, 60L, 61L, 62L, 62L, 62L, 62L, 62L,
    63L, 64L, 64L, 65L, 66L, 67L, 68L, 68L, 69L, 70L, 70L, 71L, 72L,
    73L, 74L, 75L, 75L, 75L, 76L, 76L, 77L, 77L, 78L, 79L, 80L, 81L,
    82L, 83L, 84L, 85L, 86L, 86L, 86L, 87L, 88L, 89L, 90L, 91L, 92L,
    93L, 94L, 95L, 96L, 97L, 98L, 99L, 99L, 100L, 100L, 101L, 101L,
    102L, 103L, 104L, 105L, 105L, 105L, 106L, 107L, 108L, 108L, 109L,
    110L, 111L, 112L, 113L, 114L, 115L, 115L, 115L, 116L, 117L, 118L,
    119L, 120L, 121L, 122L, 123L, 124L, 125L, 125L, 126L, 126L, 127L,
    128L, 128L, 129L, 130L, 131L, 132L, 133L, 134L, 135L, 135L, 136L,
    137L, 138L, 139L, 140L, 141L, 142L, 142L, 143L, 144L, 144L, 145L,
    145L, 146L, 147L, 148L, 149L, 149L, 150L, 151L, 152L, 152L, 152L,
    153L, 154L, 155L, 156L, 157L, 158L, 158L, 158L, 158L, 159L, 159L,
    159L, 160L, 161L, 162L, 163L, 164L, 165L, 165L, 166L, 167L, 168L,
    168L, 169L, 170L, 171L, 172L, 173L, 174L, 174L, 174L, 175L, 176L,
    176L, 177L, 177L, 177L, 178L, 179L, 180L, 181L, 182L, 183L, 184L,
    185L, 186L, 187L, 187L, 187L, 187L, 188L, 188L, 189L, 190L, 190L,
    191L, 191L, 191L, 192L, 193L, 194L, 194L, 195L, 196L, 197L, 198L,
    199L, 199L, 200L, 201L, 202L, 203L, 204L, 204L, 204L, 204L, 204L,
    205L, 206L, 207L, 208L, 209L, 210L, 211L, 212L, 212L, 213L, 213L,
    214L, 215L, 216L, 217L, 217L, 217L, 217L, 218L, 218L, 218L, 219L,
    220L, 221L, 221L, 222L, 223L, 223L, 224L, 225L, 226L, 227L, 228L,
    228L, 228L, 229L, 229L, 230L, 230L, 231L, 232L, 232L, 233L, 233L,
    233L, 234L, 234L, 234L, 234L, 234L, 235L, 236L, 236L, 237L, 238L,
    239L, 239L, 239L, 240L, 240L, 241L, 242L, 243L, 244L, 244L, 245L,
    246L, 247L, 248L, 249L, 249L, 250L, 251L, 252L, 253L, 253L, 253L,
    253L, 254L, 255L, 256L, 257L, 258L, 259L, 259L, 259L, 259L, 260L,
    261L, 261L, 262L, 262L, 263L, 263L, 263L, 263L, 263L, 264L, 264L,
    265L, 265L, 266L, 267L, 267L, 267L, 268L, 269L, 270L, 271L, 271L,
    272L, 272L, 273L, 274L, 275L, 276L, 276L, 277L, 278L, 279L, 279L,
    280L, 281L, 281L, 281L, 281L, 281L, 281L, 281L, 282L, 283L, 284L,
    284L, 284L, 285L, 285L, 286L, 287L, 288L, 289L, 290L, 291L, 292L,
    292L, 293L, 294L, 295L, 296L, 297L, 298L, 299L, 299L, 300L, 300L,
    301L, 302L, 303L, 303L, 304L, 305L, 306L, 307L, 307L, 307L, 307L,
    307L, 308L, 308L, 308L, 309L, 310L, 311L, 312L, 313L, 314L, 315L,
    316L, 317L, 318L, 319L, 320L, 321L, 322L, 323L, 323L, 324L, 325L,
    326L, 326L, 326L, 327L, 328L, 328L, 329L, 330L, 330L, 331L, 332L,
    333L, 333L, 334L, 335L, 336L, 337L, 337L, 337L, 337L, 338L, 339L,
    340L, 341L, 342L, 343L, 344L, 344L, 345L, 345L, 346L, 347L, 348L,
    349L, 350L, 351L, 352L, 352L, 352L, 353L, 354L, 354L, 354L, 355L,
    356L, 356L, 356L, 356L, 357L, 358L, 358L, 359L, 359L, 360L, 360L,
    361L, 362L, 363L, 364L, 364L, 364L, 364L, 365L, 366L, 367L, 368L,
    369L, 370L, 371L, 371L, 372L, 373L, 374L, 374L, 375L, 376L, 377L,
    378L, 379L, 379L, 380L, 381L, 382L, 383L, 384L, 385L, 386L, 386L,
    387L, 387L, 388L, 389L, 390L, 391L, 392L, 393L, 394L, 395L, 396L,
    396L, 397L, 397L, 398L, 399L, 400L, 401L, 402L, 403L, 404L, 405L,
    405L, 406L, 407L, 408L, 409L, 410L, 411L, 411L, 412L, 412L, 413L,
    414L, 415L, 416L, 417L, 417L, 417L, 418L, 419L, 419L, 419L, 420L,
    421L, 421L, 422L, 423L, 423L, 424L, 425L, 426L, 427L, 428L, 429L,
    430L, 431L, 431L, 432L, 433L, 433L, 434L, 435L, 436L, 437L, 438L,
    439L, 440L, 440L, 441L, 442L, 443L, 444L, 445L, 446L, 446L, 447L,
    448L, 449L, 450L, 450L, 451L
  ), independ = c(
    "x", "x", "x", "y",
    "y", "z", "y", "y", "x", "x", "x", "y", "x", "x", "x", "x", "y",
    "x", "x", "x", "x", "x", "x", "x", "y", "z", "y", "z", "y", "y",
    "x", "x", "x", "x", "x", "z", "y", "x", "x", "z", "x", "x", "x",
    "x", "y", "z", "y", "y", "x", "x", "y", "x", "x", "x", "x", "x",
    "x", "y", "x", "x", "x", "x", "x", "z", "x", "x", "x", "z", "x",
    "x", "x", "x", "y", "x", "x", "x", "x", "x", "x", "x", "x", "x",
    "x", "x", "x", "x", "x", "x", "x", "x", "y", "x", "x", "z", "x",
    "x", "y", "x", "z", "x", "x", "x", "x", "x", "x", "x", "x", "y",
    "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x",
    "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "z", "x",
    "y", "x", "x", "x", "y", "x", "y", "x", "y", "y", "y", "x", "x",
    "z", "y", "x", "x", "x", "x", "x", "x", "y", "y", "y", "x", "z",
    "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "z",
    "z", "x", "x", "x", "y", "x", "x", "x", "y", "x", "x", "x", "x",
    "x", "x", "x", "x", "x", "y", "y", "z", "z", "x", "x", "x", "x",
    "x", "x", "y", "x", "x", "y", "z", "x", "z", "y", "y", "x", "x",
    "y", "y", "y", "y", "y", "y", "x", "x", "y", "x", "x", "x", "x",
    "x", "x", "z", "x", "y", "x", "x", "x", "x", "z", "x", "x", "z",
    "y", "x", "x", "x", "x", "y", "x", "x", "x", "x", "z", "z", "x",
    "z", "x", "x", "x", "x", "x", "x", "x", "z", "x", "x", "x", "x",
    "x", "x", "z", "x", "z", "x", "x", "x", "y", "x", "z", "x", "x",
    "x", "x", "x", "y", "x", "x", "x", "x", "x", "x", "z", "x", "z",
    "x", "x", "x", "x", "z", "z", "x", "x", "x", "y", "x", "x", "z",
    "x", "x", "x", "x", "x", "y", "y", "y", "x", "z", "x", "x", "y",
    "y", "y", "y", "x", "y", "z", "y", "z", "y", "y", "y", "x", "y",
    "y", "y", "y", "x", "x", "x", "x", "x", "y", "z", "y", "x", "y",
    "x", "z", "y", "x", "y", "z", "z", "x", "y", "y", "z", "y", "y",
    "x", "y", "x", "x", "x", "z", "x", "y", "y", "x", "y", "y", "z",
    "z", "z", "z", "y", "x", "y", "x", "y", "y", "z", "y", "z", "y",
    "y", "x", "x", "x", "y", "x", "x", "z", "x", "x", "y", "x", "x",
    "y", "y", "z", "y", "z", "y", "x", "z", "y", "y", "y", "y", "y",
    "x", "y", "y", "x", "y", "y", "x", "y", "z", "x", "y", "y", "z",
    "y", "z", "y", "y", "x", "x", "x", "y", "x", "y", "y", "x", "y",
    "y", "y", "z", "x", "x", "z", "x", "y", "z", "x", "y", "y", "y",
    "y", "x", "y", "y", "y", "x", "x", "y", "y", "y", "y", "y", "y",
    "x", "y", "x", "y", "y", "x", "x", "x", "z", "y", "y", "y", "y",
    "x", "x", "z", "y", "z", "x", "z", "x", "x", "x", "x", "y", "y",
    "z", "y", "z", "z", "y", "x", "x", "z", "y", "y", "z", "y", "y",
    "x", "x", "z", "y", "y", "z", "y", "y", "y", "z", "y", "y", "y",
    "y", "z", "y", "x", "y", "y", "z", "z", "y", "z", "z", "y", "z",
    "x", "y", "y", "z", "y", "z", "y", "z", "x", "y", "y", "z", "z",
    "z", "x", "z", "x", "z", "y", "x", "x", "z", "y", "x", "y", "y",
    "y", "y", "y", "x", "y", "y", "z", "z", "y", "y", "x", "z", "z",
    "z", "y", "x", "y", "y", "z", "z", "z", "y", "y", "x", "x", "z",
    "z", "y", "z", "y", "z", "z", "x", "z", "y", "z", "y", "z", "y",
    "y", "y", "y", "y", "y", "z", "x", "y", "y", "y", "y", "y", "y",
    "y", "y", "y", "x", "y", "z", "z", "y", "y", "z", "y", "y", "x",
    "y", "z", "y", "y", "y", "z", "z", "x", "y", "y", "z", "y", "y",
    "y", "y", "y", "z", "y", "x", "y", "y", "y", "y", "z"
  ), switch = c(
    FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE,
    FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
  )), row.names = c(
    NA,
    -639L
  ), class = c("data.frame"))
$\endgroup$
1
  • $\begingroup$ Does each row correspond to a new therapy start? $\endgroup$
    – dipetkov
    Oct 8, 2022 at 15:13

1 Answer 1

2
$\begingroup$

If you fit the model with a conditional logistic regression, not making any random-effect assumptions about ID, it works

> library(survival)
> clogit(switch~independ+strata(ID),data=d)
Call:
clogit(switch ~ independ + strata(ID), data = d)

            coef exp(coef) se(coef)     z       p
independy  3.665    39.041    1.406 2.606 0.00916
independz  1.704     5.494    1.151 1.480 0.13888

Likelihood ratio test=13.02  on 2 df, p=0.001492
n= 639, number of events= 24 

That suggests there's an issue with estimating the random effects or their variance, which is spilling over into estimation of the regression coefficients. Since most of the information about the regression coefficients will come from within-ID comparisons, if you aren't interested specifically in the ID variance component you might be better off with conditional logistic regression.

[This approach doesn't always apply -- sometimes there is substantial between-stratum information, and sometimes the variance components are of substantive interest -- but it's nice and simple when it does apply]

$\endgroup$
1
  • $\begingroup$ Thanks Thomas. As I've never heard about conditional logistic regression, I will need to look into that - sounds as if this could be very much what I need... Will need a few days to dig into it:) $\endgroup$
    – tjebo
    Oct 9, 2022 at 22:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.