【发布时间】:2020-08-25 08:21:34
【问题描述】:
我正在尝试使用 r 编程中的准确度函数来寻找预测模型的准确度。但我在 R Studio 中收到以下错误。我是否必须更改预测变量的模式或其他东西?我已经将类视为 ts,将模式视为数字。
我不明白为什么,任何帮助将不胜感激。以下是完整代码。
输入结果:
dput(Enrollment_Data)
structure(list(COUNT = c(17L, 1L, 5L, 8L, 45L, 21L, 18L, 43L,
82L, 116L, 192L, 289L, 242L, 254L, 335L, 138L, 71L, 98L, 91L,
138L, 175L, 232L, 155L, 376L, 197L, 271L, 421L), Enrolment_date = structure(c(25L,
20L, 5L, 10L, 8L, 16L, 1L, 18L, 14L, 12L, 3L, 26L, 23L, 21L,
6L, 11L, 9L, 17L, 2L, 19L, 15L, 13L, 4L, 27L, 24L, 22L, 7L), .Label = c("APR2018",
"APR2019", "AUG2018", "AUG2019", "DEC2017", "DEC2018", "DEC2019",
"FEB2018", "FEB2019", "JAN2018", "JAN2019", "JUL2018", "JUL2019",
"JUN2018", "JUN2019", "MAR2018", "MAR2019", "MAY2018", "MAY2019",
"NOV2017", "NOV2018", "NOV2019", "OCT2018", "OCT2019", "SEP2017",
"SEP2018", "SEP2019"), class = "factor")), class = "data.frame", row.names = c(NA,
-27L))
数据:
COUNT Enrolment_date
1 17 SEP2017
2 1 NOV2017
3 5 DEC2017
4 8 JAN2018
5 45 FEB2018
6 21 MAR2018
7 18 APR2018
8 43 MAY2018
9 82 JUN2018
10 116 JUL2018
11 192 AUG2018
12 289 SEP2018
13 242 OCT2018
14 254 NOV2018
15 335 DEC2018
16 138 JAN2019
17 71 FEB2019
18 98 MAR2019
19 91 APR2019
20 138 MAY2019
21 175 JUN2019
22 232 JUL2019
23 155 AUG2019
24 376 SEP2019
25 197 OCT2019
26 271 NOV2019
27 421 DEC2019
错误:
> accuracy(forecast1)
Error in accuracy.default(forecast1) :
First argument should be a forecast object or a time series.
完整代码:
Enrollment_Data <- read.csv('RateT0.csv')
head(Enrollment_Data)
#load packages
library(tseries)
library(ggplot2)
library(forecast)
attach(Enrollment_Data)
#Data Exploration
plot(COUNT)
#Forecasting Returns
adf.test(COUNT, alternative="stationary")
d.COUNT <- diff(COUNT, differences = 3)
summary(COUNT)
summary(d.COUNT)
plot(d.COUNT)
adf.test(d.COUNT, alternative="stationary")
acf(d.COUNT)
pacf(d.COUNT)
#Step 2: Model Estimation
forecast::auto.arima(d.COUNT)
#Step 4: Diagnosis
arima.final <-arima(d.COUNT, c(3,0,0))
tsdiag(arima.final)
'Choose the one that has least AIC and significant co-efficients'
#arima.final <-arima(COUNT, c(3,3,1))
forecast1 <- predict(arima.final,n.ahead = 12)
forecast1
summary(forecast1)
accuracy(forecast1)
plot(d.COUNT)
【问题讨论】:
-
问题未正确提出。您没有提供数据或最小示例来直接测试您的代码。下次提供一个可重现的例子。看看这个:stackoverflow.com/help/how-to-ask