timeDifCompare

This report aims to explain the relationship between the errors and the Interval hours of the time daily maxinum ozone occured and the time that inputs variables happend for predictions(from 1- 12 ocolck)

# load TimeDifTestData from HORA.1 TO HORA.12 files and rbind them
# together.
load("~/HORA1/timeDifTestData.RData")
timeDifHora1 <- timeDifTestData
load("~/HORA2/timeDifTestData.RData")
timeDifHora2 <- timeDifTestData
load("~/HORA3/timeDifTestData.RData")
timeDifHora3 <- timeDifTestData
load("~/HORA4/timeDifTestData.RData")
timeDifHora4 <- timeDifTestData
load("~/HORA5/timeDifTestData.RData")
timeDifHora5 <- timeDifTestData
load("~/HORA6/timeDifTestData.RData")
timeDifHora6 <- timeDifTestData
load("~/HORA7/timeDifTestData.RData")
timeDifHora7 <- timeDifTestData
load("~/HORA8/timeDifTestData.RData")
timeDifHora8 <- timeDifTestData
load("~/HORA9/timeDifTestData.RData")
timeDifHora9 <- timeDifTestData
load("~/HORA10/timeDifTestData.RData")
timeDifHora10 <- timeDifTestData
load("~/HORA11/timeDifTestData.RData")
timeDifHora11 <- timeDifTestData
load("~/HORA12/timeDifTestData.RData")
timeDifHora12 <- timeDifTestData
timeDifTotal <- rbind(timeDifHora1, timeDifHora2, timeDifHora3, timeDifHora4, 
    timeDifHora5, timeDifHora6, timeDifHora7, timeDifHora8, timeDifHora9, timeDifHora10, 
    timeDifHora11, timeDifHora12)

# To check the frequency of the timeDif
library(PerformanceAnalytics)
table(timeDifTotal$timeDif)
## 
## -11 -10  -9  -8  -7  -6  -5  -4  -3  -2  -1   0   1   2   3   4   5   6 
##   1   1   1   2   4   4   4   4   4   3   4   9  44 124 229 300 331 340 
##   7   8   9  10  11  12  13  14  15  16  17  18  21  22  23 
## 326 320 307 304 298 291 263 203 106  41   7   1   1   1   1
# the range of colume 'timeDif' is between -11 to 23 ,but without 19,20


# save test errors of different models based on different 'timeDif' (-11
# to 23 without 19,20)
source("~/function/modelErrors.r")
for (i in c(-11:18, 21:23)) {
    t <- timeDifTotal[round(timeDifTotal$timeDif) == i, ]
    lmError <- modelErrors(t[, "lmFit"], t[, "realO3"])
    lmError <- as.data.frame(cbind(ErrorTimeDif = lmError, timeDif = i, model = "lm", 
        type = c("MAE", "RMSE", "RELE")))
    svmError <- modelErrors(t[, "svmFit"], t[, "realO3"])
    svmError <- as.data.frame(cbind(ErrorTimeDif = svmError, timeDif = i, model = "svm", 
        type = c("MAE", "RMSE", "RELE")))
    nnetError <- modelErrors(t[, "nnetFit"], t[, "realO3"])
    nnetError <- as.data.frame(cbind(ErrorTimeDif = nnetError, timeDif = i, 
        model = "nnet", type = c("MAE", "RMSE", "RELE")))
    rfError <- modelErrors(t[, "rfFit"], t[, "realO3"])
    rfError <- as.data.frame(cbind(ErrorTimeDif = rfError, timeDif = i, model = "rf", 
        type = c("MAE", "RMSE", "RELE")))
    linearError <- modelErrors(t[, "linearFit"], t[, "realO3"])
    linearError <- as.data.frame(cbind(ErrorTimeDif = linearError, timeDif = i, 
        model = "linear", type = c("MAE", "RMSE", "RELE")))
    greedyError <- modelErrors(t[, "greedyFit"], t[, "realO3"])
    greedyError <- as.data.frame(cbind(ErrorTimeDif = greedyError, timeDif = i, 
        model = "greedy", type = c("MAE", "RMSE", "RELE")))
    save(lmError, svmError, nnetError, rfError, linearError, greedyError, file = paste(i, 
        "timeDifError.RData"))
}


# combine -11 to 23 timeDif and different models together into a file
# timeDifErrorTotal.RData
load("~/timeDifTestCompare/-11 timeDifError.RData")
lmErrorTotal <- lmError
svmErrorTotal <- svmError
nnetErrorTotal <- nnetError
rfErrorTotal <- rfError
linearErrorTotal <- linearError
greedyErrorTotal <- greedyError
for (i in c(-10:18, 21:23)) {
    load(file = paste(i, "timeDifError.RData"))
    lmErrorTotal <- rbind(lmErrorTotal, lmError)
    svmErrorTotal <- rbind(svmErrorTotal, svmError)
    nnetErrorTotal <- rbind(nnetErrorTotal, nnetError)
    rfErrorTotal <- rbind(rfErrorTotal, rfError)
    linearErrorTotal <- rbind(linearErrorTotal, linearError)
    greedyErrorTotal <- rbind(greedyErrorTotal, greedyError)
}
errorTotal <- rbind(lmErrorTotal, svmErrorTotal, nnetErrorTotal, rfErrorTotal, 
    linearErrorTotal, greedyErrorTotal)
save(errorTotal, file = ("timeDifErrorTotal.RData"))

# get out of the rows which error type is MAE
dataMAE <- subset(errorTotal, type == "MAE")
library(lattice)
dMAE <- dataMAE
dMAE[, 1] <- as.numeric(as.character(dataMAE[, 1]))
dMAE[, 2] <- as.numeric(as.character(dataMAE[, 2]))
xyplot(ErrorTimeDif ~ timeDif | model, data = dMAE, type = "l", main = "MAE")

plot of chunk timeDifCompare


# get out of the rows which error type is MAE
dataMAE <- subset(errorTotal, type == "MAE")
library(lattice)
dMAE <- dataMAE
dMAE[, 1] <- as.numeric(as.character(dataMAE[, 1]))
dMAE[, 2] <- as.numeric(as.character(dataMAE[, 2]))
xyplot(ErrorTimeDif ~ timeDif | model, data = dMAE, type = "l")

plot of chunk timeDifCompare


# get out of the rows which error type is RMSE
dataRMSE <- subset(errorTotal, type == "RMSE")
library(lattice)
dRMSE <- dataRMSE
dRMSE[, 1] <- as.numeric(as.character(dataRMSE[, 1]))
dRMSE[, 2] <- as.numeric(as.character(dataRMSE[, 2]))
xyplot(ErrorTimeDif ~ timeDif | model, data = dRMSE, type = "l", main = "RMSE")

plot of chunk timeDifCompare


# get out of the rows which error type is RELE
dataRELE <- subset(errorTotal, type == "RELE")
library(lattice)
dRELE <- dataRELE
dRELE[, 1] <- as.numeric(as.character(dataRELE[, 1]))
dRELE[, 2] <- as.numeric(as.character(dataRELE[, 2]))
xyplot(ErrorTimeDif ~ timeDif | model, data = dRELE, type = "l", main = "RELE")

plot of chunk timeDifCompare