我有4年的连续数据与医院患者的随机遭遇有关,auto.arima和预测的执行时间很长(超过1小时),请帮助。
```{R Reading Data }
library(lubridate)
library(zoo)
library(ggplot2)
library(tseries)
setwd("S:/Software/R/file1")
data <- read.csv("datahosp.csv")
data$ServiceDate <- mdy(data$ServiceDate)
EDdata <- data[data$Status == "ED",]
IPOPdata <- data[data$Status == "IPOP",]
```
Time Series Plot For Emergency Department Encounters Data
```{R Data For Emergency Department}
ed <- subset(EDdata, select = c(Encounters, ServiceDate))
head(ed)
eds <- seq(as.Date("2012-04-01"), as.Date("2017-04-25"), by = "day")
y<-ts(ed$Encounters, start = c(2012,as.numeric(format(eds[1],"%j"))), frequency = 365)
print("Time Series Plot For Emergency Department")
ggplot(ed, aes(ServiceDate, Encounters)) + geom_line() + scale_x_date('month') + ggtitle("Time Series Plot Of No Of Encounters In The Emergecy Department")
```
Forecast using ARIMA (Autoregressive Integrated Moving Average) Forecasting Method for Emergency Department
```{R ARIMA Forecast ED}
library(forecast)
newfit <- auto.arima(y, D = 1)
print(newfit)
newfitf <- forecast(newfit, h = 60)
plot(newfitf, ylab = "Encounters", xlab = "Time", main = "ARIMA Forecast For Emergency Department Encounters")
write.csv(newfitf, file = "edforecast.csv")
```
Forecast for IP+OP Department
```{R Data For IPOP Department}
ipop <- subset(IPOPdata, select = c(Encounters, ServiceDate))
ipopd <- seq(as.Date("2012-04-01"), as.Date("2017-04-25"), by = "day")
yt<-ts(ipop$Encounters, start = c(2012, as.numeric(format(ipopd[1],"%j"))), frequency = 365)
print("Time Series Plot For IPOP")
ggplot(ipop, aes(ServiceDate, Encounters)) + geom_line() + scale_x_date('month') + ggtitle("Time Series Plot Of No Of Encounters InPatient and Observation")
```
Forecast using ARIMA (Autoregressive Integrated Moving Average) Forecasting Method for Emergency Department
```{R ARIMA Forecast IPOP}
library(forecast)
newfit2 <- auto.arima(yt, D = 1)
print(newfit2)
newfitf2 <- forecast(newfit2, h = 60)
plot(newfitf2, ylab = "Encounter", xlab = "Time", main = "ARIMA Forecast For IPOP Encounters")
write.csv(newfitf, file = "ipopforecast.csv")
```
最初它执行正常,但代码中的微小更改现在需要很长时间才能执行而无需任何输出。
这是连续4年每日遭遇的时间序列数据
如果我把它分成两半,它会在15到20分钟的时间内完成。有人可以帮忙解决这个问题。