【问题标题】:Converting a data-frame into time series in R在 R 中将数据帧转换为时间序列
【发布时间】:2022-11-01 12:55:19
【问题描述】:

我在一列中有 3 年的每日数据,需要在 R 中编写代码以将数据帧转换为时间序列对象,但我不确定编码。我附上原始数据。我想知道是将频率设置为每月还是每天,或者是否调整原始数据以使其在 R 中更加用户友好。任何建议/帮助将不胜感激。 谢谢 马丁。

我无法加载代码。然后我将频率更改为仅一年零 1,它接受了数据,但并没有给出完整的画面。

This is the R code
`install.packages("readxl")
install.packages("forecast")
install.packages("tseries")

library(readxl)
library(forecast)
library(tseries)
asb <- read_excel("C://Users//BCCAMNHY//OneDrive - Birmingham City Council//HomeFiles//My Documents//DATA ANALYST TRAINING//PROJECT 4//PROJECT DOCUMENTS//ASB_311022.xlsx")

View(asb)
class(
asbtime=ts(asb$`ASB Submitted`,start = min(asb$`Date for R`,end = max(asb$`Date for R`),frequency = 12)
class(asbtime)
library(forecast)
library(tseries)
plot(asbtime)
acf(asbtime)
pacf(asbtime)
adf.test(asbtime)
gdpmodel=auto.arima(gdptime,ic="aic",trace = TRUE) ## dont understand this line of code
acf(ts(asb$residuals)) # not sure if this code should be changed to asb$asb submitted
pacf(ts(asb$residuals))# as above
myasbforecast=forecast(asbmodel,level = c(95),h=10*4) ##### Don't understand this line of code.  Want a monthly or daily forecast - think ideally monthly
mygdpforecast
plot(asbforecast)
Box.test(myasbforecast$resid, lag=5, type= "Ljung-Box")
Box.test(mygdpforecast$resid, lag=15, type= "Ljung-Box")
Box.test(myasbforecast$resid, lag=25, type= "Ljung-Box")
An extract of the raw data is:
Submitted   Count of Submitted
01/03/2019  1
02/03/2019  0
03/03/2019  0
04/03/2019  0
05/03/2019  1
06/03/2019  0
07/03/2019  1
08/03/2019  2
09/03/2019  0
10/03/2019  0
11/03/2019  27
12/03/2019  54
13/03/2019  52
14/03/2019  46
15/03/2019  44

【问题讨论】:

    标签: r statistics timeserieschart


    【解决方案1】:

    在您的示例中,数据列的名称与代码中使用的名称不匹配。我认为这是一个巧合,但无论如何都要检查一下。 恕我直言,这些将足以转换为 ts:

    asbtime=ts(asb$`Count of Submitted`, start=2019, frequency = 365)
    plot(forecast(asbtime), xlab = "year", ylab="Submitted")
    

    【讨论】:

      猜你喜欢
      • 2017-12-13
      • 2020-03-14
      • 1970-01-01
      • 1970-01-01
      • 2021-04-05
      • 2018-02-08
      • 2016-04-09
      相关资源
      最近更新 更多