首页 > 解决方案 > NeweyWest - 长度为零的参数

问题描述

嗨,我是 R 的新手,所以这是我的问题:

我正在尝试使用 fama french 模型复制有关加密货币的资产定价的硕士论文主题。基本上我得到了论坛:

r=beta1*rm+beta2*SMB+beta3*HML

我计算了 rm、SMB 和 HML(364 个条目内的所有向量)以及 364 个条目内的历史回报 r。(rm 命名为 CRIX,指的是基准)我现在检查是否可以只使用 lm 函数进行回归(效果很好),但异方差性测试表明我需要使用稳健的标准误差,所以我会使用 NeweyWest功能,但总是得到错误:

Error in if (ncol(x) == 1) { : argument is of length zero

 bitcoin <- lm(formula = returns_daily[,"bitcoin"]~CRIX+SMB+HML)

summary(bitcoin)

Call:
lm(formula = returns_daily[, "bitcoin"] ~ CRIX + SMB + HML)

Residuals:
      Min        1Q    Median        3Q       Max 
-0.218119 -0.028217  0.000865  0.029360  0.252865 
Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.005456   0.002867   1.903 0.057856 .  
CRIX         0.193845   0.051950   3.731 0.000221 ***
SMB          0.038500   0.034388   1.120 0.263637    
HML         -0.067920   0.034054  -1.994 0.046856 *  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.05312 on 360 degrees of freedom
Multiple R-squared:  0.0532,    Adjusted R-squared:  0.04531 
F-statistic: 6.743 on 3 and 360 DF,  p-value: 0.0001952

coeftest(bitcoin)
t test of coefficients:
              Estimate Std. Error t value  Pr(>|t|)    
(Intercept)  0.0054561  0.0028673  1.9029 0.0578556 .  
CRIX         0.1938453  0.0519501  3.7314 0.0002212 ***
SMB          0.0385002  0.0343879  1.1196 0.2636373    
HML         -0.0679199  0.0340543 -1.9945 0.0468558 *  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

> coeftest(bitcoin,vcov=NeweyWest(bitcoin))
Error in if (ncol(x) == 1) { : argument is of length zero

NeweyWest(bitcoin)
Error in if (ncol(x) == 1) { : argument is of length zero

我的输入向量都具有相同的长度,并且我没有缺失值,所以我真的不明白为什么我的 NeweyWest-Test 不起作用。有关如何跟踪我的错误的任何建议?

标签: rstandard-error

解决方案


刚刚遇到同样的错误,但幸运地找到了解决方案,即使用参数向lm函数提供数据data。把这个留给后代,因为,我想,这样的问题对于作者来说几乎不可能在 7 个月的时间内过期。


推荐阅读