"invalid term in model formula" error when running the garchFit function in the fGarch R package

226 views Asked by At

I want to run the examples in the help document of the garchFit() function in the fGarch R library, and come against the following error: "Error in terms.formula(formula, data = data) : invalid term in model formula"

Here's the first example in the help document:

   # 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)

I am using R version 4.1.3. and version 3042.83.2 of fGarch.

Any suggestions, etc., will be greatly appreciated.

1

There are 1 answers

0
Quinten On

When I run your code, there is no error but only a warning:

> 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.