我想要使用新lme4软件包(当前的开发人员版本)的新bootMer()功能。我是R新手,不知道应该为FUN参数编写哪个函数。它说它需要一个数值向量,但我不知道该功能会执行什么。所以我有一个混合模型公式,它被转换到bootMer(),并且有许多重复项。所以我不知道这个外部函数做了什么?它应该是自举方法的模板吗? bootMer中没有引导方法吗?那么为什么他们需要一个外部的“利益统计”呢?我应该使用哪种统计数据?R:使用新的lme4软件包的bootMer()引导二进制混合模型logistic回归
下面的语法是否适合工作? R一直在产生FUN必须是数值向量的错误。我不知道如何将估算与“合适”分开,甚至我应该这样做呢?我可以说我迷失了这个“乐趣”的说法。此外,我不知道应该使用变量“Mixed5”传递混合模型glmer()公式,还是应该传递一些指针和引用?我在例子中看到的是X(bootMer(第一个参数)是* 11聚物()对象我想写* Mixed5但它呈现的错误
非常感谢
我的代码。:
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
-------------------------------- ------------------------更新------------------------- ----------------------------
我编辑了像本指导的代码。代码运行得很好,但SE和Biases都是零。你也知道如何从这个输出中提取P值(对我来说很陌生)?我应该使用混合()的afex包吗?
我修改后的代码:
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 --------------------------- --------------------------
我也试过以下,但代码生成警告,并没有给出任何结果。
(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 ------------------------- ----------------------------
此代码以及生成警告:
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
许多非常感谢您的帮助很大亲爱奔:) – Vic
我相应的修改代码(在我的问题的更新),并将其顺利无误跑。然而我有两个问题:所有的偏见和SE都是零。 2:这些线是什么? (我的意思是t1,t2 ...)?原始引导重采样?有没有什么办法从这个输出中提取估计值和P值? – Vic
(1)你应该**不要**在'FUN'内重新运行你的模型 - 只需要使用'fixef()'调用。 (2)输出中的't1','t2',...是固定效应估计值。 (3)你一定要看看'?confint.merMod' ... –