jon*_*nyf 5 r standard-error hierarchical-data lme4
我正在使用模拟数据估计混合效应模型。其基础是联合实验:研究中有 N 个国家和 P 个参与者,每个受访者都会看到该实验两次。这意味着有 NxPx2 个观测值。国家层面的数据中引入了异质性,因此我运行了一个混合效应模型,使用lmer随国家/地区而异的随机效应来解释这种差异。然而,由于每个受访者都会进行两次实验,因此我还想在个人层面上对我的标准误差进行聚类。我的数据和模型看起来像这样:
library(lme4)
data(iris)
# generating IDs for observations
iris <- iris %>% mutate(id = rep(1:(n()/2), each = 2))
#run model
mod <- lmer(Sepal.Length~Sepal.Width+Petal.Length+Petal.Width + (Sepal.Width+Petal.Length+Petal.Width || Species), data=iris, REML = F, control = lmerControl(optimizer = 'bobyqa'))
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用该包获取集群 SE parameters:
library(parameters)
param <- model_parameters(
mod,
robust = TRUE,
vcov_estimation = "CR",
vcov_type = "CR1",
vcov_args = list(cluster = iris$id)
)
Run Code Online (Sandbox Code Playgroud)
这会返回一个错误:
Error in vcovCR.lmerMod(obj = new("lmerModLmerTest", vcov_varpar = c(0.00740122363004, : Non-nested random effects detected. clubSandwich methods are not available for such models.
Run Code Online (Sandbox Code Playgroud)
我不拘泥于任何一种方法或任何东西。我只想返回此类模型规范的集群 SE。截至目前,我找不到任何执行此操作的软件包。有谁知道如何做到这一点,或者这样的模型是否有意义?我是传销新手,但我在想,如果我将其作为一个简单的线性模型来运行,我会lm_robust按个人进行聚类,所以对我来说,我也应该在这里做同样的事情,这是有意义的。