【发布时间】:2017-06-07 13:59:45
【问题描述】:
我有一个数据框,我想将其转换为 ts 并从 DOC 3 或 SampleDate 2007-06-23 开始预测 AvgWeight。 AvgWeight 每周估计一次 (DOC)。我想比上一个 DOC (101) 提前 3 周进行预测,所以我基本上想要预测 DOC 108、115 和 122。这个列表中的人可以帮我预测下面的这个小数据集吗?
DOC AvgWeight PondName SampleDate
1 3 1.000000 Pond01 2007-06-23
2 10 1.666667 Pond01 2007-06-30
3 17 2.066667 Pond01 2007-07-07
4 24 2.275000 Pond01 2007-07-14
5 31 3.833333 Pond01 2007-07-21
6 38 6.200000 Pond01 2007-07-28
7 45 7.400000 Pond01 2007-08-04
8 52 8.500000 Pond01 2007-08-11
9 59 10.250000 Pond01 2007-08-18
10 66 11.100000 Pond01 2007-08-25
11 73 13.625000 Pond01 2007-09-01
12 80 15.200000 Pond01 2007-09-08
13 87 16.375000 Pond01 2007-09-15
14 94 17.800000 Pond01 2007-09-22
15 101 21.500000 Pond01 2007-09-29
这是上面要复制到R的数据集的dput
wt <- structure(list(DOC = c(3, 10, 17, 24, 31, 38, 45, 52, 59, 66,
73, 80, 87, 94, 101), AvgWeight = c(1, 1.66666666666667, 2.06666666666667,
2.275, 3.83333333333333, 6.2, 7.4, 8.5, 10.25, 11.1, 13.625,
15.2, 16.375, 17.8, 21.5), PondName = structure(c(1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "Pond01", class =
"factor"), SampleDate = structure(c(1182585600, 1183190400,
1183795200, 1184400000, 1185004800, 1185609600, 1186214400, 1186819200,
1187424000, 1188028800, 1188633600, 1189238400, 1189843200,
1190448000, 1191052800), class = c("POSIXct", "POSIXt"))), .Names =
c("DOC", "AvgWeight", "PondName", "SampleDate"), row.names = c(NA, 15L
), class = "data.frame")
wt$SampleDate <- as.Date(wt$SampleDate)
wt
我试过了;
library(forecast)
library(ggplot2)
pond <- ts(wt$AvgWeight,start=3,frequency=52,end=101)
autoplot(pond)
但是我的 ts 呼叫已关闭。我正在阅读有关 ts 的信息,但还不能掌握。我很感激任何帮助。
【问题讨论】:
标签: r ggplot2 time-series forecasting