我是R语言的新手我尝试使用以下数据集
Site Name Utility Unit Date 00:00 00:30 01:00 01:30 02:00 02:30 3-8
Whitehall
Place Electricity kWh 06-03-2010 60.8 60.7 58.7 59.79 60.8 59.3 3-8
Whitehall
Place Electricity kWh 06-04-2010 62.21 57.01 60.2 58.81 59.71 60.81
3-8 Whitehall
Place Electricity kWh 06-05-2010 58.4 59.91 58.71 60.61 59.41 61.71
3-8 Whitehall
Place Electricity kWh 06-06-2010 60.26 60.27 61.26 60.27 60.07 64.36
3-8 Whitehall
Place Electricity kWh 06-07-2010 59.36 60.17 58.07 60.07 57.66 59.97
3-8 Whitehall
Place Electricity kWh 06-08-2010 57.47 60.26 58.27 58.37 56.37 60.56
3-8 Whitehall
Place Electricity kWh 06-09-2010 68.99 61.94 61.85 57.38 58.49 58.86
3-8 Whitehall
Place Electricity kWh 06-10-2010 62.72 62.65 57.5 57.32 58.06 61.57
3-8 Whitehall
Place Electricity kWh 06-11-2010 64.89 68.5 59.85 58.85 61.35 63.53
3-8 Whitehall
Place Electricity kWh 06-12-2010 66.66 58.15 58.43 57.25 60.71 60.04
代码:
请帮助我每天,每周,每月和每季度绘制数据,使用时间序列分解上瘾时间序列
input <- read.csv("~/HomeElectricityForecast/data/input.csv")
View(input)
rdate <- as.Date(input$Date,"%m/%d/%y")
plot(input$X0.00 ~ rdate, type="l", col="red",xlab="Date", ylab="Units", main="Electricity Forecast - Line Graph")
box()
plot(input$X0.00 ~ rdate, type="p", col="green",xlab="Date", ylab="Units", main="Electricity Forecast - Point Graph")
# tsWeek <- ts(input$X0.00,frequency=7)
tsWeek <- ts(input[,2],frequency=53,start=c(2010,51))
tsDaily <- ts(input[,2],frequency=365,start=c(2010,20))
tsMonthly <- ts(input[,2],frequency=12,start=c(2010,30))
tsQuaterly <- ts(input[,2],frequency=4,start=c(2010,120))
library(forecast)
fit <- ets(tsWeek)
fc <- forecast(fit)
plot(fc)
y <- msts(input$X0.00, seasonal.periods=c(7,365.25))
fit <- tbats(y)
fc <- forecast(fit)
plot(fc)
#ARIMA Weekly
fitWeek <- arima(tsWeek, order=c(1,0,1), list(order=c(0,1,0), period=53))
fc <- forecast(fitWeek) plot(fc)
#ARIMA Daily
fitDaily <- arima(tsDaily, order=c(3,1,3), list(order=c(0,1,0), period=330))
fc <- forecast(fitDaily)
plot(fc)
#ARIMA Monthly
fitMonthly <- arima(tsMonthly, order=c(1,0,0), list(order=c(0,1,0), period=11))
fc <- forecast(fitMonthly) plot(fc)
#ARIMA Quaterly
fitQuaterly <- arima(tsQuaterly, order=c(0,0,0), list(order=c(0,1,0), period=4))
fc <- forecast(fitQuaterly) plot(fc)
install.packages("fArma")
library(fArma)
#ARMA model
fitWeek_ARMA <- armaFit(~arma(1,1),data=tsWeek)
#Forecasting 10 weeks with test dataset.
predict(fitWeek_ARMA, newdata=testData_ByWeek,n.ahead=10,n.back=8, conf=c(80,95), doplot=TRUE)
#ARMA model Daily
fitDaily_ARMA <- armaFit(~arma(3,3),data=tsDaily)
#Forecasting daily with test dataset.
predict(fitDaily_ARMA, newdata=testData_ByDaily,n.ahead=10,n.back=8, conf=c(80,95), doplot=TRUE)
#ARMA model Monthly
fitMonthly_ARMA <- armaFit(~arma(1,0),data=tsMonthly)
#Forecasting Monthly with test dataset.
predict(fitMonthly_ARMA, newdata=testData_ByMonthly,n.ahead=20,n.back=8, conf=c(80,95), doplot=TRUE)
#ARMA model Quaterly
fitQuaterly_ARMA <- armaFit(~arma(0,0),data=tsQuaterly)
#Forecasting Quaterly with test dataset.
predict(fitQuaterly_ARMA, newdata=testData_ByQuaterly,n.ahead=20,n.back=8, conf=c(80,95), doplot=TRUE)
请为此提供帮助