【发布时间】:2020-07-18 23:16:21
【问题描述】:
我正在执行 Mincer Zarnowitz 来测试时间序列回归的拟合优度。测试(https://eranraviv.com/volatility-forecast-evaluation-in-r/)归结为,首先,对拟合值的观测值进行回归,其次,回归的截距为 0,拟合值的系数为 1 的联合测试。
我附上了我的观察向量 (obs) 和拟合值 (fit) 的前 20 个观察结果 - 它对整个数据集给出了相同的错误。使用R,我首先在fit上运行obs的回归(MZ2),并保存。然后我使用包car中的linearHypothesis函数来检验上面的联合假设。矩阵 (MZ2$model) 的秩最大 (2),因此矩阵是可逆的。然而我收到了错误Error in solve.default(vcov.hyp) : system is computationally singular: reciprocal condition number = 6.22676e-17。代码运行单一假设检验。
我不明白为什么会出现此错误。 summary 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 并且很难解决。你能按比例缩小你的合身度和观察值吗,比如 fit/1e6
-
成功了。如果您正确回答问题,我会给您信用。谢谢!
标签: r matrix regression hypothesis-test singular