You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在R中使用PLM对象执行稳健F检验时遇报错求助

问题:在R中使用plm对象运行稳健F检验时出错

代码与错误信息

运行的代码:

library('wooldridge')
data(wagepan,package='wooldridge')
library('plm')
pdata<-pdata.frame(wagepan,index=c("nr","year"))
fdreg<-plm(lwage~educ*(d81+d82+d83+d84+d85+d86+d87)+union,data=pdata,model="fd")
summary(fdreg)
library('car')
H0<-matchCoefs(fdreg,"educ")
linearHypothesis(fdreg,H0)
linearHypothesis(fdreg,H0,vcov=vcovHC(fdreg,"HC1"))

触发的错误:

'arg' should be one of “arellano”, “white1”, “white2”

错误原因

plm包内置的vcovHC()函数,针对一阶差分模型(model="fd")时,仅支持"arellano"、"white1"、"white2"这三种方差估计类型,你传入的"HC1"不在允许列表内,因此抛出错误。

解决方法

  • 方法1:使用plm支持的方差类型
    直接替换为plm允许的参数值,比如"white1"或"white2",修改后的代码:
linearHypothesis(fdreg, H0, vcov = vcovHC(fdreg, "white1"))
  • 方法2:用sandwich包实现HC1稳健方差
    如果必须使用HC1类型的稳健方差,可以调用sandwich包的vcovHC()函数(注意区分plm包同名函数),代码如下:
library(sandwich)
# 计算HC1类型的稳健方差矩阵
hc1_vcov <- vcovHC(fdreg, type = "HC1")
# 传入linearHypothesis
linearHypothesis(fdreg, H0, vcov = hc1_vcov)

内容的提问来源于stack exchange,提问作者AKJ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 23:39:08