我想对这些数据进行adf.test
BarCodeComm.Output = Chr$(201) & "CD000"
然后我得到了错误
timeseries=structure(list(Data = structure(c(10L, 13L, 16L, 19L, 22L, 25L,
30L, 33L, 2L, 5L, 8L, 11L, 14L, 17L, 20L, 23L, 26L, 29L, 31L,
34L, 3L, 6L, 9L, 12L, 15L, 18L, 21L, 24L, 27L, 4L, 7L, 10L, 13L,
16L, 19L, 22L, 25L, 28L, 30L, 33L, 2L, 5L, 8L, 11L, 14L, 17L,
20L, 23L, 26L, 29L, 31L, 34L, 3L, 6L, 9L, 12L, 15L, 18L, 21L,
24L, 27L, 32L, 1L, 4L, 7L, 10L, 13L, 16L, 19L, 22L, 25L, 28L,
30L, 33L, 2L, 5L, 8L, 11L, 14L, 17L, 20L, 23L, 26L, 29L, 31L,
34L, 3L, 6L, 9L, 12L, 15L, 18L, 21L, 24L, 27L, 32L, 1L, 4L, 16L,
22L, 33L, 2L, 5L, 20L, 31L, 6L, 9L, 15L, 27L, 10L), .Label = c("01.01.2016",
"01.01.2017", "01.01.2018", "01.02.2016", "01.02.2017", "01.02.2018",
"01.03.2016", "01.03.2017", "01.03.2018", "01.04.2016", "01.04.2017",
"01.04.2018", "01.05.2016", "01.05.2017", "01.05.2018", "01.06.2016",
"01.06.2017", "01.06.2018", "01.07.2016", "01.07.2017", "01.07.2018",
"01.08.2016", "01.08.2017", "01.08.2018", "01.09.2016", "01.09.2017",
"01.09.2018", "01.10.2016", "01.10.2017", "01.11.2016", "01.11.2017",
"01.12.2015", "01.12.2016", "01.12.2017"), class = "factor"),
client = c(11629L, 11629L, 11629L, 11629L, 11629L, 11629L,
11629L, 11629L, 11629L, 11629L, 11629L, 11629L, 11629L, 11629L,
11629L, 11629L, 11629L, 11629L, 11629L, 11629L, 11629L, 11629L,
11629L, 11629L, 11629L, 11629L, 11629L, 11629L, 11629L, 11633L,
11633L, 11633L, 11633L, 11633L, 11633L, 11633L, 11633L, 11633L,
11633L, 11633L, 11633L, 11633L, 11633L, 11633L, 11633L, 11633L,
11633L, 11633L, 11633L, 11633L, 11633L, 11633L, 11633L, 11633L,
11633L, 11633L, 11633L, 11633L, 11633L, 11633L, 11633L, 11658L,
11658L, 11658L, 11658L, 11658L, 11658L, 11658L, 11658L, 11658L,
11658L, 11658L, 11658L, 11658L, 11658L, 11658L, 11658L, 11658L,
11658L, 11658L, 11658L, 11658L, 11658L, 11658L, 11658L, 11658L,
11658L, 11658L, 11658L, 11658L, 11658L, 11658L, 11658L, 11658L,
11658L, 11661L, 11661L, 11661L, 11661L, 11661L, 11661L, 11661L,
11661L, 11661L, 11661L, 11661L, 11661L, 11661L, 11661L, 11683L
), stuff = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 1L), .Label = c("00564СМР- Магнит ТС",
"00843ТМН- X5 Retail Group", "02129СМР- X5 Retail Group",
"02182СМР- X5 Retail Group", "02289СМР- Магнит ТС"), class = "factor"),
Sales = c(24L, 32L, 29L, 30L, 35L, 14L, 27L, 34L, 40L, 35L,
38L, 22L, 29L, 27L, 29L, 21L, 21L, 18L, 20L, 33L, 28L, 27L,
32L, 28L, 26L, 22L, 17L, 23L, 11L, 16L, 45L, 19L, 19L, 27L,
18L, 28L, 19L, 20L, 14L, 22L, 26L, 35L, 20L, 23L, 36L, 34L,
35L, 20L, 18L, 14L, 15L, 20L, 16L, 21L, 19L, 14L, 18L, 11L,
10L, 12L, 14L, 9L, 7L, 3L, 4L, 5L, 1L, 5L, 3L, 4L, 5L, 6L,
5L, 8L, 6L, 3L, 3L, 4L, 6L, 6L, 3L, 2L, 7L, 5L, 1L, 5L, 4L,
4L, 8L, 4L, 5L, 5L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L,
1L, 1L, 1L, 2L, 1L, 1L, 1L, 6L)), class = "data.frame", row.names = c(NA,
-110L))
#test adf
library("tseries")
library(dplyr);timeseries %>% group_by(client, stuff) %>% summarise(stat = adf.test(Sales)$statistic, pval = adf.test(Sales)$p.value)
怎么了?这个错误是什么意思? 我该如何纠正行为迪基-全面测试。 我怀疑mydata数据存在问题,但是我无法理解哪些问题。 我该如何处理我的数据以纠正错误?
答案 0 :(得分:1)
问题似乎出在一组观察中。对于一组,只有一个观察值。在这种情况下,请使用if/else
timeseries %>%
group_by(client, stuff) %>%
summarise(stat = if(n() == 1) NA else adf.test(Sales)$statistic,
pval = if(n()== 1) NA else adf.test(Sales)$p.value)
# A tibble: 5 x 4
# Groups: client [?]
# client stuff stat pval
# <int> <fct> <dbl> <dbl>
#1 11629 00843ТМН- X5 Retail Group -2.53 0.369
#2 11633 02289СМР- Магнит ТС -2.42 0.410
#3 11658 02129СМР- X5 Retail Group -2.72 0.293
#4 11661 02182СМР- X5 Retail Group -2.51 0.378
#5 11683 00564СМР- Магнит ТС NA NA