[R] error in arfima...

akshay kulkarni @k@h@y_e4 @end|ng |rom hotm@||@com
Sun Jun 4 13:24:41 CEST 2023

Dear Martin,
                     REgrets to reply this late....

I am staring at a conundrum never before encountered in my experience with R:

[1] 45.40  3.25  6.50  2.15
> arfima(LYGH[[201]])
 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)
> arfima(c(45.40,3.25,6.50,2.15))

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

sigma[eps] = 18.01252
a list with components:
 [1] "log.likelihood"  "n"               "msg"             "d"               "ar"
 [6] "ma"              "covariance.dpq"  "fnormMin"        "sigma"           "stderror.dpq"
[11] "correlation.dpq" "h"               "d.tol"           "M"               "hessian.dpq"
[16] "length.w"        "residuals"       "fitted"          "call"            "x"
[21] "series"

Please note that the index of LYGH has changed from 202 to 201 due to some randomness in one of my function.


Output of dput LYGH[[201]]:

> dput(LYGH[[201]])
c(45.4, 3.25, 6.5, 2.14999999999998)

output of session info()

R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server x64 (build 14393)

Matrix products: default

[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

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

other attached packages:
[1] pbmcapply_1.5.1 imputeTS_3.3    forecast_8.17.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7        urca_1.3-3        pillar_1.9.0      compiler_4.1.2    tseries_0.10-51
 [6] tools_4.1.2       xts_0.12.1        nlme_3.1-153      lifecycle_1.0.3   tibble_3.2.1
[11] gtable_0.3.3      lattice_0.20-45   pkgconfig_2.0.3   rlang_1.1.0       cli_3.6.1
[16] rstudioapi_0.14   curl_4.3.2        xml2_1.3.3        dplyr_1.1.1       generics_0.1.3
[21] vctrs_0.6.1       gridtext_0.1.5    ggtext_0.1.2      lmtest_0.9-40     grid_4.1.2
[26] nnet_7.3-16       tidyselect_1.2.0  glue_1.6.2        R6_2.5.1          fansi_1.0.4
[31] ggplot2_3.4.2     TTR_0.24.3        magrittr_2.0.3    scales_1.2.1      quantmod_0.4.20
[36] timeDate_4021.106 colorspace_2.1-0  fracdiff_1.5-1    quadprog_1.5-8    utf8_1.2.3
[41] stinepack_1.4     munsell_0.5.0     zoo_1.8-10

PLease Also note:

arfima(c(45.4, 3.25, 6.5, 2.14999999999998))

  arfima(y = c(45.4, 3.25, 6.5, 2.14999999999998))

sigma[eps] = 18.01252
a list with components:
 [1] "log.likelihood"  "n"               "msg"             "d"               "ar"
 [6] "ma"              "covariance.dpq"  "fnormMin"        "sigma"           "stderror.dpq"
[11] "correlation.dpq" "h"               "d.tol"           "M"               "hessian.dpq"
[16] "length.w"        "residuals"       "fitted"          "call"            "x"
[21] "series"

Many thanks in advance....

Thanking you,
Yours sincerely,

From: Martin Maechler <maechler using stat.math.ethz.ch>
Sent: Thursday, June 1, 2023 1:28 PM
To: akshay kulkarni <akshay_e4 using hotmail.com>
Cc: R help Mailing list <r-help using r-project.org>
Subject: Re: [R] error in arfima...

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

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

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

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

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

 [1] LC_CTYPE=de_CH.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=de_CH.UTF-8
 [7] LC_PAPER=de_CH.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=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

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

Maybe you need to


{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


   so we get your exact data


   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 Maechler
ETH Zurich  and  R Core team

	[[alternative HTML version deleted]]

More information about the R-help mailing list