【发布时间】:2016-02-16 10:02:26
【问题描述】:
滚动窗口回归估计如下: data= datam,每个周期 60 个窗口
datam=cbind(unempts,gdpts)
datam <-matrix(datam,ncol=2)
out <- rollapplyr(datam,
width = 60,
FUN = function(x) coef(lm(as.data.frame(x))),
by.column=FALSE)
plot((out[,2]),type="l")
在此图中,还需要通过使用 HAC 和非 HAC SE 作为斜率系数来添加置信区间。为了获得我尝试过的 SE
coeftest(out[,2],vcov. = out[,2]$hacse)
但我得到一个错误 -
错误:$ 运算符对原子向量无效
请告知我哪里出错了。
【问题讨论】:
-
您需要更多详细信息。您要输入什么样的数据。这通常发生在您的子集错误时。
-
@AbdalahEl-Barrad 输入输出的数据是来自 lm 的系数,[,1] 表示截距,[,2] 表示斜率
-
head(outm) (拦截) V2 [1,] 7.046241 -0.3939213 [2,] 6.962879 -0.3867624 [3,] 6.750484 -0.3423529 [4,] 6.557447 -0.2992243 [5,] 6.4 0.2718148 [6,] 6.383905 -0.2631228
-
试试 coeftest(out, vcov. = hacse)
-
@AbdalahEl-Barrad 也是同样的错误。此代码是有人建议的。您能确定创建的回归对象是什么吗?我对 out 和 x 感到困惑。
标签: r confidence-interval standard-error