tensor_predictors/sim/plots.R

62 lines
2.4 KiB
R

if (!endsWith(getwd(), "/sim")) {
setwd("sim")
}
date <- "20221007" # yyyymmdd, to match all "[0-9]{6}"
time <- "[0-9]{4}" # HHMM, to match all "[0-9]{4}"
sim <- Reduce(rbind, Map(function(path) {
df <- read.csv(path)
df$n <- as.integer(strsplit(path, "[-.]")[[1]][[4]])
df
}, list.files(".", pattern = paste0(
"^sim-normal-", date, "T", time, "-[0-9]+[.]csv$", collapse = ""
))))
stats <- aggregate(. ~ n, sim, mean)
q75 <- aggregate(. ~ n, sim, function(x) quantile(x, 0.75))
q25 <- aggregate(. ~ n, sim, function(x) quantile(x, 0.25))
colors <- c(gmlm = "#247407", hopca = "#2a62b6", pca = "#a11414", tsir = "#9313b9")
line.width <- 1.75
margins <- c(5.1, 4.1, 4.1, 0.1)
with(stats, {
par(mar = margins)
plot(range(n), c(0, 1.05),
type = "n", bty = "n", main = "Estimation Error",
xlab = "Sample Size", ylab = "Error")
lines(n, dist.projection.gmlm, col = colors["gmlm"], lwd = line.width)
lines(n, dist.projection.hopca, col = colors["hopca"], lwd = line.width)
lines(n, dist.projection.pca, col = colors["pca"], lwd = line.width)
lines(n, dist.projection.tsir, col = colors["tsir"], lwd = line.width)
par(mar = rep(0, 4))
legend("topright", legend = names(colors), col = colors, lwd = line.width,
lty = 1, bty = "n")
par(mar = margins)
})
with(stats, {
par(mar = margins)
plot(range(n), c(0, 1.05),
type = "n", bty = "n", main = "Root Mean Squared Prediction Error",
xlab = "Sample Size", ylab = "Error")
xn <- c(q75$n, rev(q25$n))
polygon(x = xn, y = c(q75$error.pred.gmlm, rev(q25$error.pred.gmlm)),
col = adjustcolor(colors["gmlm"], alpha.f = 0.3), border = NA)
polygon(x = xn, y = c(q75$error.pred.hopca, rev(q25$error.pred.hopca)),
col = adjustcolor(colors["hopca"], alpha.f = 0.3), border = NA)
polygon(x = xn, y = c(q75$error.pred.pca, rev(q25$error.pred.pca)),
col = adjustcolor(colors["pca"], alpha.f = 0.3), border = NA)
lines(n, error.pred.gmlm, col = colors["gmlm"], lwd = line.width)
lines(n, error.pred.hopca, col = colors["hopca"], lwd = line.width)
lines(n, error.pred.pca, col = colors["pca"], lwd = line.width)
lines(n, error.pred.tsir, col = colors["tsir"], lwd = line.width)
par(mar = rep(0, 4))
legend("topright", legend = names(colors), col = colors, lwd = line.width,
lty = 1, bty = "n")
par(mar = margins)
})