我希望在garchFit()函数的帮助文档中运行fGarch R库中的示例,并针对以下错误:“terms.formula中的错误(公式,数据=数据):模型公式中的无效项”
下面是帮助文档中的第一个示例:
# In the univariate case the lhs formula has not to be specified ...
# A numeric Vector from default GARCH(1,1) - fix the seed:
N = 200
x.vec = as.vector(garchSim(garchSpec(rseed = 1985), n = N)[,1])
garchFit(~ garch(1,1), data = x.vec, trace = FALSE)我使用的是R版本4.1.3。以及fGarch的3042.83.2版本。
如有任何建议等,将不胜感激。
发布于 2022-04-23 13:18:38
当我运行您的代码时,没有错误,只有一个警告:
> library(fGarch)
> # A numeric Vector from default GARCH(1,1) - fix the seed:
> N = 200
> x.vec = as.vector(garchSim(garchSpec(rseed = 1985), n = N)[,1])
> garchFit(~ garch(1,1), data = x.vec, trace = FALSE)
Title:
GARCH Modelling
Call:
garchFit(formula = ~garch(1, 1), data = x.vec, trace = FALSE)
Mean and Variance Equation:
data ~ garch(1, 1)
<environment: 0x7fd065608dc8>
[data = x.vec]
Conditional Distribution:
norm
Coefficient(s):
mu omega alpha1 beta1
3.5418e-05 1.0819e-06 8.8855e-02 8.1200e-01
Std. Errors:
based on Hessian
Error Analysis:
Estimate Std. Error t value Pr(>|t|)
mu 3.542e-05 2.183e-04 0.162 0.871
omega 1.082e-06 1.051e-06 1.030 0.303
alpha1 8.885e-02 5.450e-02 1.630 0.103
beta1 8.120e-01 1.242e-01 6.538 6.25e-11 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Log Likelihood:
861.9494 normalized: 4.309747
Description:
Sat Apr 23 15:14:55 2022 by user:
Warning message:
Using formula(x) is deprecated when x is a character vector of length > 1.
Consider formula(paste(x, collapse = " ")) instead. https://stackoverflow.com/questions/71979900
复制相似问题