【问题标题】:Problems when adjusting time series for seasonality with seas function in R在 R 中使用海洋函数调整季节性时间序列时的问题
【发布时间】:2021-02-08 00:07:12
【问题描述】:

当我尝试在 R 中调整我的季度时间序列数据集以适应季节性时遇到问题。我已将数据集“ASPUS”加载到 R 并使用以下代码指定它的日期:

ASPUS <- read.csv(file = "ASPUS.csv", header=TRUE, sep=",")
ASPUS$DATE <- as.Date(ASPUS$DATE, "%Y-%m-%d")

数据集的头部如下所示:

        DATE     ASPUS
1 1963-01-01 100.00000
2 1963-04-01 100.51813
3 1963-07-01  99.48187
4 1963-10-01 101.55440
5 1964-01-01 101.55440

数据集的目的是将其作为时间序列进行分析。因此,我使用 ts 函数来创建时间序列对象:

ASPUSts <- ts(ASPUS, frequency = 4, start = 1963)

但是,此函数在日期列中返回负数,如下所示:

         DATE     ASPUS
1963 Q1 -2557 100.00000
1963 Q2 -2467 100.51813
1963 Q3 -2376  99.48187
1963 Q4 -2284 101.55440
1964 Q1 -2192 101.55440
1964 Q2 -2101 104.66321

我的问题出现在下一步,我尝试使用 seas 函数调整季节性:

ASPUS1 <- seas(ASPUSts)

因为我收到此错误:

    Error: X-13 run failed

Errors:
- Seasonal MA polynomial with initial parameters is
  noninvertible with root(s) inside the unit circle. RESPECIFY
  model with different initial parameters.

Warnings:
- Automatic transformation selection cannot be done on a series
  with zero or negative values.
- The covariance matrix of the ARMA parameters is singular, so
  the standard errors and the correlation matrix of the ARMA
  parameters will not be printed out.
- The covariance matrix of the ARMA parameters is singular, so
  the standard errors and the correlation matrix of the ARMA
  parameters will not be printed out.

是否有人对我如何处理这些负值或以其他方式解决问题有任何建议,以便我可以对我的数据集进行季节性调整?

【问题讨论】:

    标签: r time-series


    【解决方案1】:

    根据?ts

    说明:

     The function ‘ts’ is used to create time-series objects.
    
     ‘as.ts’ and ‘is.ts’ coerce an object to a time-series and test
     whether an object is a time series.
    

    用法:

     ts(data = NA, start = 1, end = numeric(), frequency = 1,
        deltat = 1, ts.eps = getOption("ts.eps"), class = , names = )
     as.ts(x, ...)
     is.ts(x)
    

    参数:

    data: a vector or matrix of the observed time-series values. A data
          frame will be coerced to a numeric matrix via ‘data.matrix’.
          (See also ‘Details’.)
    

    这里,要注意的关键是:“数据:观察到的时间序列值的向量或矩阵”。 IE。您不应输入日期向量作为ts 的输入。

    这是ts 的正确语法。

    ASPUSts <- ts(ASPUS$ASPUS, frequency = 4, start = 1963)
    

    在您的示例中,seas 实际上是在尝试季节性调整转换为 -2557、-2467、... 的日期时间序列(旁注:内部 R 将日期计算为与 1970-01-01 的差异; 这就是为什么 60 年代的日期显示为负数)。

    【讨论】:

      猜你喜欢
      • 2021-03-18
      • 1970-01-01
      • 2016-10-28
      • 2021-11-02
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 2017-03-11
      • 2022-08-19
      相关资源
      最近更新 更多