r - R中的季节调整包(人口普查局)仅调整一半数据

标签 r date time-series arima

我已经设法让 library(seasonal) 包在我的一半数据(第 2 列和第 8 列)上完美运行,但它拒绝季节性调整另一半数据。我真的很困惑,因为代码运行良好并且没有显示错误,所以我想知道这是否是我的数据的一个功能(我是时间序列的新手)或者我的代码中是否存在隐藏的错误?

head(x)
        Date European Maori Pacific Peoples Asian MELAA Other Ethnicity Total
1 2004-09-30      7.9  17.9            14.8  15.4  13.4            14.1   9.7
2 2004-12-31      7.9  18.6            13.3  20.9  14.3            14.9   9.9
3 2005-03-31      7.8  17.8            14.6  21.1  12.6            16.1   9.8
4 2005-06-30      7.6  18.1            11.9  20.4  12.6            13.7   9.4
5 2005-09-30      7.1  17.4            10.5  16.1   9.4            19.2   9.0
6 2005-12-31      7.6  15.9             9.8  16.6  11.1            12.0   9.3

代码如下:

*请注意,季节性调整在 sub1 和 sub2 中运行平稳。 sub3sub4 中没有发生季节性调整

library(tidyverse)
library(seasonal)

x <- read.csv("HLF524501_20191112_083700_50.csv", header = TRUE, check.names = FALSE, stringsAsFactors = FALSE)
x <- x %>% 
        mutate(Date = ifelse(substring(Date, 5, nchar(x)) == "Q3", paste(substring(Date, 0, 4), "09-30", sep = "-"),
                             ifelse(substring(Date, 5, nchar(x)) == "Q4", paste(substring(Date, 0, 4), "12-31", sep = "-"),
                                    ifelse(substring(Date, 5, nchar(x)) == "Q1", paste(substring(Date, 0, 4), "03-31", sep = "-"),
                                           paste(substring(Date, 0, 4), "06-30", sep = "-")))))
x$Date <- as.Date(x$Date)

sub1 <- x[,c(1,8)]
season0<-ts(sub1[,-1],frequency=4,start=c(2004,3))
sea1 <- seas(season0)
plot(sea1)

sub2 <- x[,c(1,2)]
season0<-ts(sub2[,-1],frequency=4,start=c(2004,3))
sea2 <- seas(season0)
plot(sea2)

sub3 <- x[,c(1,3)]
season0<-ts(sub3[,-1],frequency=4,start=c(2004,3))
sea3 <- seas(season0)
plot(sea3)

sub4 <- x[,c(1,4)]
season0<-ts(sub4[,-1],frequency=4,start=c(2004,3))
sea4 <- seas(season0)
plot(sea4)

数据如下:

dput(x)
structure(list(Date = c("2004-09-30", "2004-12-31", "2005-03-31", 
"2005-06-30", "2005-09-30", "2005-12-31", "2006-03-31", "2006-06-30", 
"2006-09-30", "2006-12-31", "2007-03-31", "2007-06-30", "2007-09-30", 
"2007-12-31", "2008-03-31", "2008-06-30", "2008-09-30", "2008-12-31", 
"2009-03-31", "2009-06-30", "2009-09-30", "2009-12-31", "2010-03-31", 
"2010-06-30", "2010-09-30", "2010-12-31", "2011-03-31", "2011-06-30", 
"2011-09-30", "2011-12-31", "2012-03-31", "2012-06-30", "2012-09-30", 
"2012-12-31", "2013-03-31", "2013-06-30", "2013-09-30", "2013-12-31", 
"2014-03-31", "2014-06-30", "2014-09-30", "2014-12-31", "2015-03-31", 
"2015-06-30", "2015-09-30", "2015-12-31", "2016-03-31", "2016-06-30", 
"2016-09-30", "2016-12-31", "2017-03-31", "2017-06-30", "2017-09-30", 
"2017-12-31", "2018-03-31", "2018-06-30", "2018-09-30", "2018-12-31", 
"2019-03-31", "2019-06-30", "2019-09-30"), European = c(7.9, 
7.9, 7.8, 7.6, 7.1, 7.6, 7.7, 6.7, 7.2, 8.5, 8.1, 7.8, 7.2, 7.7, 
9, 8.1, 8.9, 9.6, 10.8, 11.5, 12.1, 12.5, 11.4, 11.3, 10.9, 11.4, 
11.8, 11.7, 10.9, 11, 11.6, 11.8, 12.6, 12.4, 11.1, 10.7, 11.2, 
12.2, 11.2, 10.8, 10.3, 11.7, 11.3, 10.9, 11, 10.7, 11.4, 10.9, 
10.4, 11.1, 10.6, 10.1, 10, 11.1, 11, 10.4, 9.5, 11.4, 10.2, 
9.5, 8.7), Maori = c(17.9, 18.6, 17.8, 18.1, 17.4, 15.9, 17.3, 
16.1, 15.6, 18.1, 19.3, 17, 16.8, 15.9, 18.9, 16.2, 17.5, 18.9, 
21.7, 22.4, 24.9, 26.3, 25, 25.5, 25.6, 25.1, 25.8, 25.5, 25.1, 
24.5, 25, 25, 28.1, 28.4, 24, 24.7, 24.8, 25.7, 24.5, 22.9, 23.1, 
25.1, 24.4, 24, 25.1, 23.5, 25.2, 22.8, 22.9, 23.1, 22.3, 21.4, 
20.6, 21.7, 20.9, 20.3, 19, 20.9, 19.3, 17.6, 17.6), `Pacific Peoples` = c(14.8, 
13.3, 14.6, 11.9, 10.5, 9.8, 15, 12.3, 12.3, 12.6, 11.6, 15, 
9.5, 12.8, 17.6, 13.2, 15.6, 16.1, 21.3, 23.4, 25.1, 25.8, 24.4, 
25.8, 26.1, 24.8, 24.2, 25.1, 25.2, 24.2, 27.6, 27.8, 29.6, 29.2, 
27.7, 27.7, 27.2, 26.2, 24.8, 21.6, 22.4, 22.9, 23.7, 20.8, 23.9, 
21.7, 21.8, 18.8, 18.7, 19.8, 19.9, 18.9, 18.4, 18.5, 16.9, 17.4, 
14.8, 20.4, 18, 15.5, 14.1), Asian = c(15.4, 20.9, 21.1, 20.4, 
16.1, 16.6, 11.1, 12.5, 8.9, 19.6, 17.3, 14.6, 15.5, 13.3, 13.9, 
14.6, 13.4, 15.2, 16, 17, 20.6, 19.4, 18.2, 18.7, 17.9, 17.8, 
18.2, 15.2, 15.3, 19, 18.4, 18.3, 18.5, 17.8, 14, 14.7, 14.4, 
14.5, 14.9, 14.9, 13, 13.7, 15.6, 14.9, 13.7, 14.5, 17.5, 14.6, 
13.4, 12.5, 13.1, 11.3, 11.1, 13.1, 11.9, 11.1, 11.1, 12.5, 11.1, 
10.5, 9.5), MELAA = c(13.4, 14.3, 12.6, 12.6, 9.4, 11.1, 18.6, 
7, 13.7, 15.4, 19.7, 20.5, 12.1, 15.9, 25.8, 21.7, 25.6, 26.4, 
26.5, 26.9, 19.1, 28.5, 23, 21.4, 24.2, 14.5, 19.8, 25, 27.1, 
14.2, 23.7, 22.4, 23.8, 21.8, 18.3, 14.5, 21.7, 20.7, 25.5, 21.4, 
20.9, 26.2, 21.9, 25.9, 19.9, 18.7, 21.7, 19, 15.8, 23.9, 17.4, 
18.3, 17, 20.3, 17.5, 17.9, 10.9, 16.1, 14.9, 22.6, 13.5), `Other Ethnicity` = c(14.1, 
14.9, 16.1, 13.7, 19.2, 12, 9.8, 13.4, 10.1, 16.6, 10, 16.1, 
18.5, 9.2, 9.2, 13, 8.2, 9.8, 6.7, 8.6, 10.2, 9.1, 12.6, 10.6, 
8.8, 10.6, 11.1, 12.5, 12, 13.7, 15, 16.8, 12.2, 12.7, 7.9, 10.8, 
12.5, 13.2, 12.1, 12.4, 8.5, 9.5, 13.1, 12.6, 10.2, 7.8, 9.4, 
11.8, 11.9, 14.2, 13, 13.4, 12.3, 12.6, 13.4, 11.6, 13.7, 11.4, 
11.2, 13.6, 9.3), Total = c(9.7, 9.9, 9.8, 9.4, 9, 9.3, 9.4, 
8.5, 8.6, 10.3, 10.3, 9.7, 8.8, 9.2, 10.8, 9.8, 10.3, 11.2, 12.6, 
13.4, 14.6, 14.9, 13.9, 13.8, 13.7, 13.9, 14.3, 13.8, 13.4, 13.6, 
14.3, 14.4, 15.3, 14.9, 13.2, 13, 13.5, 14.4, 13.4, 12.9, 12.3, 
13.7, 13.8, 13.2, 13.2, 12.8, 13.8, 12.7, 12.2, 12.8, 12.5, 11.6, 
11.7, 12.6, 12.1, 11.7, 10.9, 12.8, 11.5, 10.8, 9.9)), class = "data.frame", row.names = c(NA, 
-61L))

非常感谢任何帮助:) 谢谢!

最佳答案

如果 seas 函数未检测到数据中的季节性,则它不包含季节性。这是基于 QS 统计数据,详细讨论如下:https://stats.stackexchange.com/questions/148573/the-results-and-specifics-from-the-qs-function-in-r

您可以使用 summary(sea1)qs(sea1)summary(sea3)qs(sea3) 查看 ARIMA 建模详细信息以及数据季节性测试。更广泛地说,建议在所有 4 个模型上使用 summary 来查看数据每个部分的建模详细信息。

关于r - R中的季节调整包(人口普查局)仅调整一半数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58816646/

相关文章:

python - 更新行的替代方法

R:具有子集的 T 统计量

r - 使用 dplyr 计算行之间的差异时间

jquery - 在日历中的特定日期之后更改背景颜色

css - 及时更改 css 属性

date - 如何直接使用时区解析日期和时间

r - match.call() 返回一个函数或一个符号,但符号不能被 do.call() 使用

r - 将两个数据框与字符串中具有特定模式的列合并

machine-learning - 如何为多种设备训练一个模型

r - 汇总时间序列数据,在 R 中获取没有 NA 或 0 的平均值