R:使用新的lme4软件包的bootMer()进行自举二进制混合模型逻辑回归 [英] R: Bootstrapped binary mixed-model logistic regression using bootMer() of the new lme4 package

查看:347
本文介绍了R:使用新的lme4软件包的bootMer()进行自举二进制混合模型逻辑回归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用新的lme4软件包(当前为开发人员版本)的新bootMer()功能.我是R的新手,不知道应该为它的FUN参数编写哪个函数.它说它需要一个数值向量,但我不知道该函数将执行什么操作.因此,我有一个混合模型公式,该公式强制转换为bootMer(),并具有许多重复项.因此,我不知道该外部函数有什么作用?它应该是引导方法的模板吗?引导程序中是否尚未实现引导方法?那么为什么他们需要一个外部的利益统计"呢?我应该使用哪个感兴趣的统计数据?

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 argument. It says it needs a numerical vector, but I have no idea what that function will perform. So I have a mixed-model formula which is cast to the bootMer(), and have a number of replicates. So I don't know what that external function does? Is it supposed to be a template for bootstrapping methods? Aren't bootstrapping methods already implemented in he bootMer? So why they need an external "statistic of interest"? And which statistic of interest should I use?

以下语法是否适合工作? R不断产生错误,指出FUN必须是数值向量.我不知道如何将估算值与拟合值"分开,甚至我应该首先这样做吗?我只能说我对有趣"的说法迷失了.我也不知道该使用变量"Mixed5"传递混合模型glmer()公式,还是应该传递一些指针和引用?我在示例中看到X(bootMer()的第一个参数是* lmer()对象.我想编写* Mixed5,但它导致了错误.

Is the following syntax proper to work on? R keeps on error generating that the FUN must be a numerical vector. I don't know how to separate the estimates from the "fit" and even should I do that in the first place? I can just say I am lost with that "FUN" argument. Also I don't know should I pass the mixed-model glmer() formula using the variable "Mixed5" or should I pass some pointers and references? I see in the examples that X (the first argument of bootMer() is a *lmer() object. I wanted to write *Mixed5 but it rendered an error.

非常感谢.

我的代码是:

library(lme4)
library(boot)

(mixed5 <- glmer(DV ~ (Demo1 +Demo2 +Demo3 +Demo4 +Trt)^2 
                 + (1 | PatientID) + (0 + Trt | PatientID)
                 , family=binomial(logit), MixedModelData4))


FUN <- function(formula) {
  fit <- glmer(DV ~ (Demo1 +Demo2 +Demo3 +Demo4 +Trt)^2 
               + (1 | PatientID) + (0 + Trt | PatientID)
               , family=binomial(logit), MixedModelData4)
  return(coef(fit))
}

result <- bootMer(mixed5, FUN, nsim = 3, seed = NULL, use.u = FALSE,
        type = c("parametric"),
        verbose = T, .progress = "none", PBargs = list())

result
FUN
fit

错误:

Error in bootMer(mixed5, FUN, nsim = 3, seed = NULL, use.u = FALSE, type = c("parametric"),  : 
  bootMer currently only handles functions that return numeric vectors

--------------------------------------------------- - - - - - 更新 - - - - - - - - - - - - - - - - - - - - -------------

-------------------------------------------------------- Update -----------------------------------------------------

我按照Ben的指示编辑了代码.该代码运行得很好,但SE和Biase均为零.您还知道如何从此输出中提取P值(对我来说很奇怪)?我应该使用afex包的mixed()吗?

I edited the code like what Ben instructed. The code ran very good but the SEs and Biases were all zero. Also do you know how to extract P values from this output (strange to me)? Should I use mixed() of afex package?

我的修改代码:

library(lme4)
library(boot)

(mixed5 <- glmer(DV ~ (Demo1 +Demo2 +Demo3 +Demo4 +Trt)^2 
                + (0 + Trt | PatientID)
                 , family=binomial(logit), MixedModelData4))


FUN <- function(fit) {
  fit <- glmer(DV ~ (Demo1 +Demo2 +Demo3 +Demo4 +Trt)^2 
               + (1 | PatientID) + (0 + Trt | PatientID)
               , family=binomial(logit), MixedModelData4)
  return(fixef(fit))
}

result <- bootMer(mixed5, FUN, nsim = 3)

result

--------------------------------------------------- ---------更新2 --------------------------------------- --------------

-------------------------------------------------------- Update 2 -----------------------------------------------------

我也尝试了以下操作,但是代码生成警告,但未给出任何结果.

I also tried the following but the code generated warnings and didn't give any result.

(mixed5 <- glmer(DV ~ Demo1 +Demo2 +Demo3 +Demo4 +Trt 
                 + (1 | PatientID) + (0 + Trt | PatientID)
                 , family=binomial(logit), MixedModelData4))

FUN <- function(mixed5) {
  return(fixef(mixed5))}

result <- bootMer(mixed5, FUN, nsim = 2)

警告消息:

In bootMer(mixed5, FUN, nsim = 2) : some bootstrap runs failed (2/2)
> result

Call:
bootMer(x = mixed5, FUN = FUN, nsim = 2)

Bootstrap Statistics :
WARNING: All values of t1* are NA
WARNING: All values of t2* are NA
WARNING: All values of t3* are NA
WARNING: All values of t4* are NA
WARNING: All values of t5* are NA
WARNING: All values of t6* are NA

--------------------------------------------------- ---------更新3 --------------------------------------- --------------

-------------------------------------------------------- Update 3 -----------------------------------------------------

此代码还生成警告:

FUN <- function(fit) {
  return(fixef(fit))}

result <- bootMer(mixed5, FUN, nsim = 2)

警告和结果:

Warning message:
In bootMer(mixed5, FUN, nsim = 2) : some bootstrap runs failed (2/2)
> result

Call:
bootMer(x = mixed5, FUN = FUN, nsim = 2)

Bootstrap Statistics :
WARNING: All values of t1* are NA
WARNING: All values of t2* are NA
WARNING: All values of t3* are NA
WARNING: All values of t4* are NA
WARNING: All values of t5* are NA
WARNING: All values of t6* are NA

推荐答案

这里基本上有两个(简单的)混淆.

There are basically two (simple) confusions here.

  • 第一个在coef()(返回矩阵列表)和fixef()(返回固定效果的向量)之间 系数):我假设您想要的是fixef(),尽管您可能想要类似c(fixef(mixed),unlist(VarCorr(mixed)))的东西.
  • 第二个是FUN应该将拟合的模型对象作为输入...
  • 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 ...

例如:

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
## 

这篇关于R:使用新的lme4软件包的bootMer()进行自举二进制混合模型逻辑回归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆