R: Bootstrapped binary mixed-model logistic regression using bootMer() of the new lme4 package

前端 未结 2 794
太阳男子
太阳男子 2021-02-06 16:53

I want to use the new bootMer() feature of the new lme4 package (the developer version currently). I am new to R and don\'t know which function should I write for its FUN argume

相关标签:
2条回答
  • 2021-02-06 17:41

    There are basically two (simple) confusions here.

    • The first is between coef() (which returns a list of matrices) and fixef() (which returns a vector of the fixed-effect coefficients): I assume that fixef() is what you wanted, although you might want something like c(fixef(mixed),unlist(VarCorr(mixed))).
    • the second is that FUN should take a fitted model object as input ...

    For example:

    library(lme4)
    library(boot)
    
    mixed <- glmer(incidence/size ~ period + (1|herd),
                   weights=size, data=cbpp, family=binomial)
    
    FUN <- function(fit) {
        return(fixef(fit))
    }
    
    result <- bootMer(mixed, FUN, nsim = 3)
    
    result
    
    ## Call:
    ## bootMer(x = mixed, FUN = FUN, nsim = 3)
    ## Bootstrap Statistics :
    ##      original      bias    std. error
    ## t1* -1.398343 -0.20084060  0.09157886
    ## t2* -0.991925  0.02597136  0.18432336
    ## t3* -1.128216 -0.03456143  0.05967291
    ## t4* -1.579745 -0.08249495  0.38272580
    ## 
    
    0 讨论(0)
  • 2021-02-06 17:44

    This might be the same problem, that I reported as an issue here. At least it leads to the same, unhelpful error message and took me a while too.

    That would mean you have missings in your data, which lmer ignores but which kill bootMer.

    Try:

    (mixed5 <- glmer(DV ~ (Demo1 +Demo2 +Demo3 +Demo4 +Trt)^2 
                     + (1 | PatientID) + (0 + Trt | PatientID)
                     , family=binomial(logit), na.omit(MixedModelData4[,c('DV','Demo1','Demo2','Demo3','Trt','PatientId')])))
    
    0 讨论(0)
提交回复
热议问题