我正在尝试使用bootcov
获取聚类标准错误,以对面板数据进行回归分析。在分析中,我将集群变量作为解决集群级混杂的固定作用。但是,将群集变量包括为固定效果会导致bootcov
引发错误(“警告消息:...在200次重新采样中出现拟合失败。请尝试增加maxit”)。我想这是因为系数矩阵根据选择的群集(here's a similar issue and solution in Stata)随引导程序复制而变化。
有人知道解决此问题的方法吗?如果没有,我可以尝试自己手动编辑该功能。不幸的是,我无法在robcov
中使用cluster选项,因为我的分析实际上需要Glm
函数而不是ols函数。此外,我想坚持使用rms
软件包,因为我的分析涉及受限制的三次样条,rms
易于可视化并通过ANOVA进行测试(尽管我可以接受其他建议)。
感谢您的帮助。我在下面复制了一个示例。
#load package
library(rms)
#make df
x <- rnorm(1000)
y <- sample(c(1:100),1000, replace=TRUE)
z <- factor(rep(1:50, 20))
df <- data.frame(y,x,z)
#set datadist
dd <- datadist(df)
options(datadist='dd')
#works when cluster variable isn't included as fixed effect in regression
reg <- ols(x ~ y, df, x=TRUE, y=TRUE)
reg_clus <- bootcov(reg, df$z)
summary(reg_clus)
#doesn't work when cluster variable included as fixed effect in regression
reg2 <- ols(x ~ y + z, df, x=TRUE, y=TRUE)
reg_clus2 <- bootcov(reg2, df$z)
summary(reg_clus2)