modelsPredictionAndPlot
This report just show the plotting of prediction and real datavalues
library(RSNNS)
library(lattice)
# make a function to plot the real and predict values based on different
# models and different matrix
predictAndPlot <- function(x) {
predAndReal <- timeDifTestData[, c("realO3", "lmFit", "svmFit", "rfFit",
"nnetFit", "greedyFit", "linearFit")]
predAndReal <- cbind(time = rep(x, nrow(predAndReal)), predAndReal)
predAndRealReshape <- reshape(predAndReal, times = names(predAndReal[, c(3:8)]),
timevar = "model", varying = list(names(predAndReal[, 3:8])), v.names = "pred",
direction = "long")
xyplot(realO3 ~ pred | model, data = predAndRealReshape, xlim = c(0, 0.7),
ylim = c(0, 0.7), main = paste("Matrix", x, "Testing"))
}
# make a function to plot prediction and real ozone values against index
library(lattice)
plotFun <- function(model, matrix) {
database <- timeDifTestData[, c("realO3", model)]
d <- reshape(database, times = names(database[, c(1:2)]), timevar = "realOrPred",
varying = list(names(database[, 1:2])), v.names = "value", direction = "long")
xyplot(value ~ id, group = realOrPred, data = d, type = "l", ylab = "Daily Maximum Ozone",
xlab = "", main = paste(matrix, "test data", model), auto.key = list(space = "right"))
}
# make a function to plot the histogram and Q-Q plot of residuals
# different models based on different matrixs
library(car)
histRes <- function(model, matrix) {
residuals <- timeDifTestData[, c("realO3")] - timeDifTestData[, c(model)]
stRes <- residuals/sd(residuals)
hist(stRes, col = "blue", main = paste("Histogram of standardized residuals based on model",
model, matrix), breaks = 15)
lines(density(stRes))
rug(jitter(stRes))
qqPlot(stRes, main = paste("Normal QQ plot of standardized residuals", model,
matrix))
}
# make a function to plot the standardized residuals against index
plotStaRes <- function(model, matrix) {
residuals <- timeDifTestData[, c("realO3")] - timeDifTestData[, c(model)]
stRes <- residuals/sd(residuals)
plot(stRes, col = "red", main = paste("residuals plot based on model", model,
matrix), ylab = "standardized residuals")
abline(h = 0)
}
load("~/HORA12/timeDifTestData.RData")
predictAndPlot(12)
plotFun("lmFit", "Matrix 12")
plotFun("rfFit", "Matrix 12")
plotFun("svmFit", "Matrix 12")
plotFun("nnetFit", "Matrix 12")
plotFun("linearFit", "Matrix 12")
plotFun("greedyFit", "Matrix 12")
histRes("lmFit", "Matrix 12")
plotStaRes("lmFit", "Matrix 12")
histRes("svmFit", "Matrix 12")
plotStaRes("svmFit", "Matrix 12")
histRes("rfFit", "Matrix 12")
plotStaRes("rfFit", "Matrix 12")
histRes("nnetFit", "Matrix 12")
plotStaRes("nnetFit", "Matrix 12")
histRes("linearFit", "Matrix 12")
plotStaRes("linearFit", "Matrix 12")
histRes("greedyFit", "Matrix 12")
plotStaRes("greedyFit", "Matrix 12")
load("~/HORA11/timeDifTestData.RData")
predictAndPlot(11)
plotFun("lmFit", "Matrix 11")
load("~/HORA10/timeDifTestData.RData")
predictAndPlot(10)
plotFun("lmFit", "Matrix 10")
load("~/HORA9/timeDifTestData.RData")
predictAndPlot(9)
plotFun("lmFit", "Matrix 9")
load("~/HORA8/timeDifTestData.RData")
predictAndPlot(8)
plotFun("lmFit", "Matrix 8")
load("~/HORA7/timeDifTestData.RData")
predictAndPlot(7)
plotFun("lmFit", "Matrix 7")
load("~/HORA6/timeDifTestData.RData")
predictAndPlot(6)
plotFun("lmFit", "Matrix 6")
load("~/HORA5/timeDifTestData.RData")
predictAndPlot(5)
plotFun("lmFit", "Matrix 5")
load("~/HORA4/timeDifTestData.RData")
predictAndPlot(4)
plotFun("lmFit", "Matrix 4")
load("~/HORA3/timeDifTestData.RData")
predictAndPlot(3)
plotFun("lmFit", "Matrix 3")
load("~/HORA2/timeDifTestData.RData")
predictAndPlot(2)
plotFun("lmFit", "Matrix 2")
load("~/HORA1/timeDifTestData.RData")
predictAndPlot(1)
plotFun("lmFit", "Matrix 1")
load("~/extendDavg/timeDifTestData.RData")
a <- "davg"
predictAndPlot(a)
plotFun("lmFit", "Matrix davg")
load("~/extendDmax/timeDifTestData.RData")
a <- "dmax"
predictAndPlot(a)
plotFun("lmFit", "Matrix dmax")