系统是 linearHypothesis 的计算奇异误差,但矩阵具有最大秩

system is computationally singular error from linearHypothesis but the matrix has maximal rank

我正在执行 Mincer Zarnowitz 来测试时间序列回归的拟合优度。测试(https://eranraviv.com/volatility-forecast-evaluation-in-r/)归结为,首先,运行对拟合值的观测值进行回归,其次,联合测试回归的截距为 0,系数为拟合值为 1.

我附上了我的观察向量 (obs) 和拟合值 (fit) 的前 20 个观察结果 - 它对整个数据集给出了相同的错误。使用 R,我首先 运行 obsfit 上的回归(MZ2)并保存。然后我使用car包中的linearHypothesis函数来检验上面的联合假设。矩阵 (MZ2$model) 的秩最大 (2),因此矩阵是可逆的。但是我收到错误 Error in solve.default(vcov.hyp) : system is computationally singular: reciprocal condition number = 6.22676e-17。单一假设检验的代码 运行s。

我不明白为什么会出现此错误。摘要 vcov 选项应该返回相同的错误来计算渐近(稳健)标准错误,但它没有。

知道这个错误吗?谢谢。

obs <-c(13964892, 10615134, 12066946,  8394110,  8991798, 12456120,  8981580,
        9261421, 12976910, 19263428,  6453574,  9025350, 12455365,  9711284,
        14876416, 11643567,  8383892, 10234233,  7601169, 10136608)
fit <- c(12478069, 11826724, 10706274, 10573869, 10413272, 10789469,
        9401626, 10067159, 12939216, 11535966, 10890038, 10634312, 11122152,
        11309619, 10877766, 10330747, 10034014, 10912567,  9204140,  9532570)
MZ2 <- lm(obs ~ fit)
summary(MZ2, vcov = vcovHC, type = "HC3")
  # Call:
  #   lm(formula = obs ~ fit)
  # 
  # Residuals:
  #   Min       1Q   Median       3Q      Max 
  # -4605688 -1518159  -543282  1318148  7130691 
  # 
  # Coefficients:
  #   Estimate    Std. Error t value Pr(>|t|)  
  # (Intercept) -7039028.9827  6717707.9500  -1.048   0.3086  
  # fit                1.6619        0.6209   2.676   0.0154 *
  #   ---
  #   Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
  # 
  # Residual standard error: 2565000 on 18 degrees of freedom
  # Multiple R-squared:  0.2847,    Adjusted R-squared:  0.2449 
  # F-statistic: 7.163 on 1 and 18 DF,  p-value: 0.0154
#
# JOINT TEST
#
require(car)
linearHypothesis(MZ2, c("(Intercept) = 0", "fit = 1"))
Error in solve.default(vcov.hyp) : 
  system is computationally singular: reciprocal condition number = 6.22676e-17
In addition: Warning message:
In constants(lhs, cnames_symb) : NAs introduced by coercion
> MZ2$rank
[1] 2
#
# UNIVARIATE TESTS
#
linearHypothesis(MZ2, c("(Intercept) = 0"))
Linear hypothesis test

Hypothesis:
(Intercept) = 0

Model 1: restricted model
Model 2: obs ~ fit

  Res.Df             RSS Df     Sum of Sq     F Pr(>F)
1     19 125618245448671                              
2     18 118396383219614  1 7221862229057 1.098 0.3086
> linearHypothesis(MZ2, c("fit = 1"))
Linear hypothesis test

Hypothesis:
fit = 1

Model 1: restricted model
Model 2: obs ~ fit

  Res.Df             RSS Df     Sum of Sq      F Pr(>F)
1     19 125870444423604                               
2     18 118396383219614  1 7474061203991 1.1363 0.3005

您的值非常大,因此当它需要计算 RSS(对残差进行平方)或重新拟合模型时,在某些时候这些数字对于机器来说可能太大了。它类似于讨论的内容

理想情况下,您返回给出预测的线性模型,并缩放因变量,例如除以 1e3 或 1e6。

你现在所拥有的,你可以做的(并测试联合假设):

df = data.frame(obs=obs/1e6,fit=fit/1e6)
MZ2 <- lm(obs ~ fit,data=df)
library(car)
linearHypothesis(MZ2, c("(Intercept) = 0", "fit = 1"))

Linear hypothesis test

Hypothesis:
(Intercept) = 0
fit = 1

Model 1: restricted model
Model 2: obs ~ fit

  Res.Df    RSS Df Sum of Sq      F Pr(>F)
1     20 126.05                           
2     18 118.40  2    7.6573 0.5821 0.5689