[R] error in arfima...

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Thu Jun 1 09:58:32 CEST 2023


>>>>> akshay kulkarni 
>>>>>     on Wed, 31 May 2023 20:55:33 +0000 writes:

    > dear members,

    > I am using arfima() from forecast package to model a time
    > series. The following is the code:

    >> LYGH[[202]]
    > [1] 45.40  3.25  6.50  2.15

    >> arfima(LYGH[[202]])
    > Error in .fdcov(x, fdf$d, h, nar = nar, nma = nma, hess = hess, fdf.work = fdf$w) :
    > NA/NaN/Inf in foreign function call (arg 5)

    > I tried viewing .fdcov() with the following code:

    > View(environment(fracdiff)$.fdcov)

    > but I see no stop() with the above mentioned error message.

    > Can you please help?

Well, as I am the maintainer of the *fracdiff* package,
I'm trying.  OTOH, as we will see below, you did not give us enough
information to really help you...

    > THanking you,
    > Yours sincerely,
    > AKSHAY M KULKARNI

Your problem is not (yet) reproducible (*)
I've done the following in an "empty" (i.e. freshly started) R
session, R 4.3.0:

----begin_R_transcript___save_as__arfima-ex.Rout__------------------------------
> 
> lN <- loadedNamespaces()
> library(forecast)
Registered S3 method overwritten by 'quantmod':
  method            from
  as.zoo.data.frame zoo 
> options(width=75)
> setdiff(loadedNamespaces(), lN) # -- see all the  *!^@...!   forecast loads:
 [1] "gtable"     "dplyr"      "tidyselect" "Rcpp"       "parallel"  
 [6] "scales"     "lattice"    "ggplot2"    "R6"         "generics"  
[11] "curl"       "lmtest"     "tibble"     "munsell"    "nnet"      
[16] "forecast"   "timeDate"   "pillar"     "rlang"      "quantmod"  
[21] "utf8"       "urca"       "quadprog"   "cli"        "magrittr"  
[26] "xts"        "grid"       "nlme"       "lifecycle"  "fracdiff"  
[31] "vctrs"      "glue"       "tseries"    "zoo"        "fansi"     
[36] "colorspace" "TTR"        "pkgconfig" 
> arfima(c(45.40, 3.25, 6.50, 2.15))

Call:
  arfima(y = c(45.4, 3.25, 6.5, 2.15)) 

Coefficients:
           d 
4.583013e-05 
sigma[eps] = 18.01252 
a list with components:
 [1] "log.likelihood"  "n"               "msg"            
 [4] "d"               "ar"              "ma"             
 [7] "covariance.dpq"  "fnormMin"        "sigma"          
[10] "stderror.dpq"    "correlation.dpq" "h"              
[13] "d.tol"           "M"               "hessian.dpq"    
[16] "length.w"        "residuals"       "fitted"         
[19] "call"            "x"               "series"         
> 
> sessionInfo()
R version 4.3.0 (2023-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Fedora Linux 36 (Thirty Six)

Matrix products: default
BLAS:   /usr/local64.sfs/app/R/R-4.3.0-inst/lib/libRblas.so 
LAPACK: /usr/lib64/liblapack.so.3.10.1

locale:
 [1] LC_CTYPE=de_CH.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=de_CH.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=de_CH.UTF-8   
 [7] LC_PAPER=de_CH.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=de_CH.UTF-8 LC_IDENTIFICATION=C       

time zone: Europe/Zurich
tzcode source: system (glibc)

attached base packages:
[1] graphics  grDevices datasets  stats     utils     methods   base     

other attached packages:
[1] forecast_8.21  fortunes_1.5-4 sfsmisc_1.1-15

loaded via a namespace (and not attached):
 [1] gtable_0.3.3      dplyr_1.1.2       compiler_4.3.0   
 [4] tidyselect_1.2.0  Rcpp_1.0.10       parallel_4.3.0   
 [7] scales_1.2.1      lattice_0.21-8    ggplot2_3.4.2    
[10] R6_2.5.1          generics_0.1.3    curl_5.0.0       
[13] lmtest_0.9-40     tibble_3.2.1      munsell_0.5.0    
[16] nnet_7.3-19       timeDate_4022.108 pillar_1.9.0     
[19] rlang_1.1.1       quantmod_0.4.22   utf8_1.2.3       
[22] urca_1.3-3        quadprog_1.5-8    cli_3.6.1        
[25] magrittr_2.0.3    xts_0.13.1        grid_4.3.0       
[28] nlme_3.1-162      lifecycle_1.0.3   fracdiff_1.5-2   
[31] vctrs_0.6.2       glue_1.6.2        tseries_0.10-54  
[34] zoo_1.8-12        fansi_1.0.4       colorspace_2.1-0 
[37] TTR_0.24.3        tools_4.3.0       pkgconfig_2.0.3  
> 
##---end__R_transcript---------------------------------------------------------------


Note that your error message pointed me to my (old, but still
fine) package {fracdiff} with its principal function fracdiff()
around which   arfima()  is a user-friendly and
generalization wrapper.

In other words arfima() calls fracdiff::fracdiff() and the error
happens there --- for you, but not for me, if I try to use the
same data as you.
I see that you must have found that too, because you mentioned
   View(environment(fracdiff)$.fdcov)

Maybe you need to

      update.packages()

{which should re-install R packages you have installed but which
 have become outdated in the mean time}

If the error persists, please send us the output of

1)
   dput(LYGH[[202]])

   so we get your exact data

2)
   sessionInfo()

   so we get much info about your R "setup"

.... last but not least:  If you are really calling arfima()
with a time series of length 4  (which your LYGH[[202]] above
seems to suggest)
then you really need to learn a bit about the tools you are
using: It really does not make any sense to fit a somewhat
sophisticated time-series model (or *any* time-series model, I'd say) 
to a "series" with 4 values.

Best regards,
Martin

--
Martin Maechler
ETH Zurich  and  R Core team



More information about the R-help mailing list