# Clear variables rm(list=ls()) library(knitr) library(forecast) source('LinearStocSystem_EDXU.R') source("Data.R")
mod_heating <- arima(dat.f$heating[1: num_obs], order = c(0, 1, 2), seasonal = list(order = c(0, 0, 2), period = 48), fixed = c(0, NA, NA, NA), include.mean = T) mod_heating plotTimeSeriesResidual(mod_heating, num_lag = 100, "ARIMA Model 3.1.4 of Heating")
setEPS() postscript("7.eps", width = 11, height = 12) plotTimeSeriesResidual(mod_heating, num_lag = 100, "ARIMA Model 3.1.4 of Heating") dev.off()
pred_heating <- predict(mod_heating, n.ahead = 4) intervalPred <- calIntervalPred(482, 13, pred_heating$pred, pred_heating$se) mat_intervalPred <- matrix(nrow = 2, ncol = 4) mat_intervalPred[1,] <- intervalPred$boundUp mat_intervalPred[2,] <- intervalPred$boundLow plotPredHeating(pred_heating$pred, mat_intervalPred, str = "ARIMA(0,1,2)(0,0,1)48 Model")
setEPS() postscript("12.eps", width = 11, height = 6) plotPredHeating(pred_heating$pred, mat_intervalPred, str = "ARIMA(0,1,2)(0,0,1)48 Model") dev.off() rm(mat_intervalPred)
ts_tempExternal <- ts(dat.f$tempExternal[1: num_obs], frequency = 48) ts_iSolar <- ts(dat.f$iSolar[1: num_obs], frequency = 48) ts_heating <- ts(dat.f$heating[1: num_obs], frequency = 48) auto.arima(ts_tempExternal, d = 1, seasonal = TRUE) auto.arima(ts_iSolar, d = 0, seasonal = TRUE) auto.arima(ts_heating, xreg = ts_tempExternal, d = 1, seasonal = TRUE) auto.arima(ts_heating, xreg = ts_iSolar, d = 0, seasonal = TRUE)
mod_tempExternal <- arima(dat.f$tempExternal[1: num_obs], order = c(0, 1, 1), seasonal = list(order = c(0, 0, 1), period = 48), include.mean = TRUE) x_1 <- dat.f$tempExternal[1: num_obs] - fitted(Arima(dat.f$tempExternal[1: num_obs], model = mod_tempExternal)) y_1 <- dat.f$heating[1: num_obs] - fitted(Arima(dat.f$heating[1: num_obs], model = mod_tempExternal)) sum(x_1 - mod_tempExternal$residuals) < 10^6 plotCCFunc(x_1, y_1, "Filtered External Temp", "Filtered Heating")
setEPS() postscript("8.eps", width = 11, height = 12) plotTimeSeriesResidual(mod_tempExternal, num_lag = 100, "ARIMA Model 1.1.1 of External Temperature") dev.off()
setEPS() postscript("10.eps", width = 11, height = 6) plotCCFunc(x_1, y_1, "Filtered External Temp", "Filtered Heating") dev.off()
mod_iSolar <- arima(dat.f$iSolar[1: num_obs], order = c(4, 0, 0), seasonal = list(order = c(0, 0, 2), period = 48), include.mean = T) x_2 <- dat.f$iSolar[1: num_obs] - fitted(Arima(dat.f$iSolar[1: num_obs], model = mod_iSolar)) y_2 <- residuals(Arima(dat.f$heating[1: num_obs], model = mod_iSolar)) sum(x_2 - mod_tempExternal$residuals) < 10^6 par(mar=c(3.5,3.5,3,1), mgp=c(2,0.7,0)) plotCCFunc(x_2, y_2, "Filtered Solar Irradiation", "Filtered Heating")
setEPS() postscript("11.eps", width = 11, height = 6) plotCCFunc(x_2, y_2, "Filtered Solar Irradiation", "Filtered Heating") dev.off()
ts_heating <- ts(dat.f$heating[1: num_obs], frequency = 48) ts_iSolar <- ts(dat.f$iSolar[1: num_obs], frequency = 48) mat_obs <- cbind(y = ts_heating, x_1 = ts_iSolar, x_2 = lag(ts_iSolar, k = - 1)) mod_heating_x <- lm(y ~ x_1 + x_2, data = mat_obs, na.action = na.omit)
mat_obs <- cbind(rep(1, 482), dat.f$iSolar[1: 482], c(dat.f$iSolar[2: 482], NaN)) residualHeating <- dat.f$heating[1: 482] - mat_obs %*% mod_heating_x$coefficients plotTimeSeriesResidual(residualHeating[1: 481], num_lag = 100)
mod_residualHeating <- auto.arima(residualHeating[1: 481]) pred_residualHeating <- predict(mod_residualHeating, n.ahead = 4)$pred
mat_x <- cbind(rep(1, 4), dat.f$iSolar[(num_obs+1): (num_obs+4)], dat.f$iSolar[(num_obs): (num_obs+3)]) pred_heating_x <- mat_x %*% mod_heating_x$coefficients pred_heating_x_residual <- pred_heating_x + pred_residualHeating # plotPredHeating(pred_heating_x, "ARIMAX Model with Known Solar Irradiation as Input") plotPredHeating(pred_heating_x_residual, "ARIMAX Model with Known Solar Irradiation as Input")
setEPS() postscript("13.eps", width = 11, height = 6) plotPredHeating(pred_heating_x_residual, "ARIMAX Model with Known Solar Irradiation as Input") dev.off()
mod_heating_3 <- arima(dat.f$heating[2: num_obs], order = c(3, 0, 4), seasonal = list(order = c(0, 0, 1), period = 48), xreg = cbind(tempExternal = dat.f$tempExternal[2: num_obs], iSolar = dat.f$iSolar[2: num_obs], iSolar_1 = dat.f$iSolar[1: num_obs-1])) mod_heating_3 plotTimeSeriesResidual(mod_heating_3$residuals, num_lag = 100)
pred_heating_3 <- predict(mod_heating_3, newxreg = cbind(tempExternal = dat.f$tempExternal[(num_obs + 1): (num_obs + 4)], iSolar = dat.f$iSolar[(num_obs + 1): (num_obs + 4)], iSolar_1 = dat.f$iSolar[num_obs: (num_obs + 3)]), n.ahead = 4)$pred plotPredHeating(pred_heating_3, "ARIMAX Model with Known Ex-Temp and Solar-Irra as Input")
mod_heating_4 <- arima(dat.f$heating[2: num_obs], order = c(3, 0, 4), seasonal = list(order = c(0, 0, 2), period = 48), xreg = cbind(tempExternal = dat.f$tempExternal[2: num_obs], iSolar = dat.f$iSolar[2: num_obs], iSolar_1 = dat.f$iSolar[1: num_obs-1])) mod_heating_4 plotTimeSeriesResidual(mod_heating_4$residuals, num_lag = 100, "Model 4")
setEPS() postscript("15.eps", width = 11, height = 12) plotTimeSeriesResidual(mod_heating_4$residuals, num_lag = 100) dev.off()
pred_heating_4 <- predict(mod_heating_4, newxreg = cbind(tempExternal = dat.f$tempExternal[(num_obs + 1): (num_obs + 4)], iSolar = dat.f$iSolar[(num_obs + 1): (num_obs + 4)], iSolar_1 = dat.f$iSolar[num_obs: (num_obs + 3)]), n.ahead = 4) intervalPred <- calIntervalPred(482, 13, pred_heating_4$pred, pred_heating_4$se) mat_intervalPred <- matrix(nrow = 2, ncol = 4) mat_intervalPred[1,] <- intervalPred$boundUp mat_intervalPred[2,] <- intervalPred$boundLow plotPredHeating(pred_heating_4$pred, mat_intervalPred, str = "ARIMAX Model with Known Ex-Temp and Solar-Irra as Input")
setEPS() postscript("14.eps", width = 11, height = 6) plotPredHeating(pred_heating_4$pred, mat_intervalPred, str = "ARIMAX Model with Known Ex-Temp and Solar-Irra as Input") dev.off()
mod_heating_5 <- arima(dat.f$heating[3: num_obs], order = c(3, 0, 4), seasonal = list(order = c(0, 0, 1), period = 48), xreg = cbind(tempExternal = dat.f$tempExternal[3: num_obs], iSolar = dat.f$iSolar[3: num_obs], iSolar_1 = dat.f$iSolar[2: (num_obs-1)], iSolar_2 = dat.f$iSolar[1: (num_obs-2)])) mod_heating_5 plotTimeSeriesResidual(mod_heating_5$residuals, num_lag = 100)
mod_heating_6 <- arima(dat.f$heating[2: num_obs], order = c(3, 1, 4), seasonal = list(order = c(0, 0, 2), period = 48), xreg = cbind(tempExternal = dat.f$tempExternal[2: num_obs], iSolar = dat.f$iSolar[2: num_obs], iSolar_1 = dat.f$iSolar[1: num_obs-1])) mod_heating_6 plotTimeSeriesResidual(mod_heating_6$residuals, num_lag = 100)
pred_heating_6 <- predict(mod_heating_6, newxreg = cbind(tempExternal = dat.f$tempExternal[(num_obs + 1): (num_obs + 4)], iSolar = dat.f$iSolar[(num_obs + 1): (num_obs + 4)], iSolar_1 = dat.f$iSolar[num_obs: (num_obs + 3)]), n.ahead = 4)$pred plotPredHeating(pred_heating_6, "ARIMAX Model with Known Solar Irradiation as Input")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.