- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想制作一个“广义线性模型的固定/随机模型”(family =“二项式”),因为我有一个数据库,其中观察来自总体并且有分组结构。然后我使用函数glmer
来自lme4
包,我也读到我可以使用 glmmPQL
库中的函数 MASS
(遥远,2006)。
当我想使用 Hausman 测试(Greene,2012)证明随机模型与固定模型的使用合理时,我的问题就出现了,我没有找到允许我执行类似于 phtest
的特定函数。测试包中的特色功能plm
.
如何证明使用随机模型的合理性?
最佳答案
这是对 plm::phtest
函数的简单调整。我已经对我实际更改的唯一代码行进行了评论。 使用风险自负,如果可能的话,根据 plm::phtest
的结果进行测试。我只是调整了代码,没有考虑它是否真的做了正确的事情!
phtest_glmer <- function (glmerMod, glmMod, ...) { ## changed function call
coef.wi <- coef(glmMod)
coef.re <- fixef(glmerMod) ## changed coef() to fixef() for glmer
vcov.wi <- vcov(glmMod)
vcov.re <- vcov(glmerMod)
names.wi <- names(coef.wi)
names.re <- names(coef.re)
coef.h <- names.re[names.re %in% names.wi]
dbeta <- coef.wi[coef.h] - coef.re[coef.h]
df <- length(dbeta)
dvcov <- vcov.re[coef.h, coef.h] - vcov.wi[coef.h, coef.h]
stat <- abs(t(dbeta) %*% as.matrix(solve(dvcov)) %*% dbeta) ## added as.matrix()
pval <- pchisq(stat, df = df, lower.tail = FALSE)
names(stat) <- "chisq"
parameter <- df
names(parameter) <- "df"
alternative <- "one model is inconsistent"
res <- list(statistic = stat, p.value = pval, parameter = parameter,
method = "Hausman Test", alternative = alternative,
data.name=deparse(getCall(glmerMod)$data)) ## changed
class(res) <- "htest"
return(res)
}
示例:
library(lme4)
gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
data = cbpp, family = binomial)
gm0 <- glm(cbind(incidence, size - incidence) ~ period + herd,
data = cbpp, family = binomial)
phtest_glmer(gm1,gm0)
## Hausman Test
## data: cbpp
## chisq = 10.2747, df = 4, p-value = 0.03605
## alternative hypothesis: one model is inconsistent
这似乎也适用于 lme
模型:
library("nlme")
fm1 <- lme(distance ~ age, data = Orthodont) # random is ~ age
fm0 <- lm(distance ~ age*Subject, data = Orthodont)
phtest_glmer(fm1,fm0)
## Hausman Test
## data: Orthodont
## chisq = 0, df = 2, p-value = 1
## alternative hypothesis: one model is inconsistent
关于r - Hausman 对 lme4 中的 "glmer"的规范测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23630214/
我正在使用广义线性混合模型(glmer、lme4-package)用 R 分析我的二项式数据集。我想使用 Tukey 的事后测试(glht,multcomp-package)对某个固定效果(“声音”)
我是 R 新手,我正在使用 glmer 来拟合几个二项式模型,我只需要它们来调用 predict使用得到的概率。但是,我有一个非常大的数据集,即使只有一个模型的大小也会变得非常大: > library
我制作了一个模型,可以查看许多变量以及对怀孕结果的影响。结果是分组的二进制文件。一群动物有 34 只怀孕和 3 只空,接下来会有 20 只怀孕和 4 只空,以此类推。 我使用 glmer 对这些数据进
问题: 我有一个数据集,其中缺少一些预测变量值。我想将已应用于这些插补集的 glmer 模型汇集在一起。我使用 mice 包来创建插补(我也使用过 amelia 和 mi 但没有成功)。我想主要提
我正在测试不同生境和柱头类型的植物柱头上花粉粒数量的差异。 我的样本设计包括两个栖息地,每个栖息地有 10 个站点。 在每个地点,我有多达 3 种柱头类型(湿、干和半干),对于每种柱头类型,我有不同数
我有关于跨纬度感染特定宿主物种的病原体多样性的数据。设计涉及在不同纬度的4个地点的3个地点收集20个人,因此我有20个人,嵌套在3个地点内,嵌套在4个地点内。 鉴于我的病原体多样性数据是带有许多零的计
我一直在用我的(非 r-savvy)大脑来让 R 产生二项式 glmer 模型的正确预测的百分比。我知道这不是统计上的 super 信息,但经常被报道;所以我也想举报。 数据: 因变量:Tipo,它有
我正在使用 glmer 并且我希望提取随机效应(截距和斜率)的方差分量的标准偏差。 我试过使用: VarCorr(model) 它返回两个标准偏差值(加上相关性),但我只想提取截距和斜率 SD 值。
我正在尝试根据我的二项式数据运行的glmer模型随时间(x轴上的天数)预测值。 Total Alive和Total Dead是计数数据。这是我的模型,以及下面的相应步骤。 full.model.dre
我的变量是在一个带有二次抽样设计的随机块上测量的,其中我的处理是 23 次加入。我有 3 个完整的块和每块 6 个样本。示例数据帧有 4 个响应变量(LH、REN、FTT、DFR)、Accesion(
生态学中的一种常见情况是具有二元结果(0 = 死亡,1 = 存活)的生存模型,其中个体(在此示例中考虑鸟类的个体嵌套尝试)在面临死亡风险的天数方面存在差异。为了解决这个问题,我们使用修改后的逻辑回归,
我希望有人能帮助我。我正在尝试进行一项分析,检查在海拔梯度上捕获的膜翅目样本的数量。我想检查与海拔相关的单峰分布以及线性分布的可能性。因此,我将 I(Altitude^2) 作为分析中的解释变量。 我
我正在尝试通过 effect来自 effects 的函数与 (gl)merMod 一起打包来自 lme4 的对象包通过lapply循环并遇到我不期望的错误。看来effect函数无法在循环内查找对象。
我正在处理面板数据集并尝试运行具有固定效果的逻辑回归。 我发现 lme4 包和 bife 包中的 glmer 模型适合这种工作。 然而,当我对每个模型进行回归时,我没有得到相同的结果(估计值、标准误差
glmmPQL 中多重随机效应的语法是什么? 使用 glmer 我的代码如下所示: fit<- glmer(A~B+C+ (1 | D)+ (1 | E), family = gaussian, da
我正在使用 R 中的 lme4 的 glmer 函数分析数据(包括在下面)。我正在构建的模型包含一个泊松分布响应变量 (obs)、一个随机因子 (area)、一个连续偏移量 (duration ),
glmmPQL 中多重随机效应的语法是什么? 使用 glmer 我的代码如下所示: fit<- glmer(A~B+C+ (1 | D)+ (1 | E), family = gaussian, da
我正在使用 R 中的 lme4 的 glmer 函数分析数据(包括在下面)。我正在构建的模型包含一个泊松分布响应变量 (obs)、一个随机因子 (area)、一个连续偏移量 (duration ),
这可能更像是一个错误报告而不是一个问题,但是:为什么显式使用 newdata 参数来使用与训练数据相同的数据集进行预测有时会产生与省略 不同的预测>newdata 参数并明确使用训练数据集? libr
出于报告原因,我试图从 glmer 模型的 emmeans 获取自由度,但它们只显示 Inf。 这是一些示例数据。在真实数据中,没有嵌套结构,这只是我构建数据框的结果: set.seed(1234)
我是一名优秀的程序员,十分优秀!