【问题标题】:Reconstruct seasonally (and non seasonally) differenced data in R在 R 中重建季节性(和非季节性)差异数据
【发布时间】:2022-01-11 04:27:09
【问题描述】:

我已经使用季节性和非季节性差异获得了用于 arima (see) 预测的固定数据。现在如何使用差异数据恢复到原始日期?

raw <- read.csv("https://raw.githubusercontent.com/thistleknot/Python-Stock/master/data/combined_set.csv",row.names=1,header=TRUE)

temp <- raw$CSUSHPINSA

#tells me to seasonally difference 1 time
print(nsdiffs(ts(temp,frequency=4)))

temp_1 <- temp-dplyr::lag(temp,1*season)

#tells me I need to difference it once more
print(ndiffs(temp_2))

temp_2 <- temp_1-dplyr::lag(temp_1,1)

#shows data is somewhat stationary
plot(temp_2)

#gives me back the original dataset if I only had seasonal differencing
na.omit(dplyr::lag(raw$CSUSHPINSA ,4)+temp_1)

#how to do this with temp_2?

一些参考资料 Pandas reverse of diff() Reverse Diff function in R

【问题讨论】:

    标签: r difference


    【解决方案1】:

    没关系,我明白了

    dplyr::lag(raw$CSUSHPINSA ,4) + dplyr::lag(temp_1,1)+temp_2
    

    更完整的例子

    temp <- raw$MSPUS
    
    #print(nsdiffs(ts(temp,frequency=4)))
    
    #temp_1 <- temp-dplyr::lag(temp,1*season)
    
    print(ndiffs(temp_1))
    
    temp_1 <- temp-dplyr::lag(temp,1)
    temp_2 <- temp_1-dplyr::lag(temp_1,1)
    
    #forecast values of temp_2
    temp_3 <- dplyr::lag(temp_1,1)+temp_2
    
    temp_4 = (dplyr::lag(raw$MSPUS ,1) + temp_3)
    
    new_temp_2_values = c(8000,10000)
    
    extended <- c(temp_4,tail(c(c(temp_3),tail(temp_4,1)+cumsum(tail(temp_3,1)+cumsum(new_temp_2_values))),length(new_temp_2_values)))
    
    print(extended)
    

    在这里写了一个更复杂的版本 https://gist.github.com/thistleknot/eeaf1631f736e20806c37107f344d50e

    【讨论】:

      猜你喜欢
      • 2020-02-21
      • 2020-07-01
      • 1970-01-01
      • 2020-06-27
      • 2015-05-03
      • 1970-01-01
      • 1970-01-01
      • 2021-11-02
      • 1970-01-01
      相关资源
      最近更新 更多