setwd("/Users/hengz/Dropbox/MyProjects/PCL/Numerical Experiments/Estimation/IllustrationExample/")
setwd("/Users/hengzhang/Dropbox/MyProjects/PCL/Numerical Experiments/Estimation/IllustrationExample/")
TempDf <- read.csv("Results/Graph4Results.csv", header = F)
SizeVec <- seq(from = 2, by = 0.2, to = 5)
# MAE
MAEMat = as.matrix(TempDf[1:16,])
MAEDf <- data.frame(Model = 'MNL', Size = SizeVec, Value = apply(MAEMat, MARGIN = 1, mean),
upp = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
low = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.1)}))
MAEMat = as.matrix(TempDf[17:32,])
MAEDf <- rbind(MAEDf, data.frame(Model = 'PCL', Size = SizeVec, Value = apply(MAEMat, MARGIN = 1, mean),
upp = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
low = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.1)})))
p1 <- ggplot(MAEDf, aes(x = Size, y = Value, group = Model)) +
geom_ribbon(data = MAEDf %>% filter(Model == "MNL"), aes(ymin = low, ymax = upp), alpha = .1) +
geom_ribbon(data = MAEDf %>% filter(Model == "PCL"), aes(ymin = low, ymax = upp), alpha = .1) +
geom_line(aes(color = Model), size = 1.5) + scale_colour_brewer(palette="Set2") + ylab('MAE') +
xlab(bquote(log[10]~'(Sample Size)'))+ theme_bw() + theme(text = element_text(size=15))
p1
# MAE
MAEMat = as.matrix(TempDf[1:16,])
MAEDf <- data.frame(Model = 'MNL', Size = SizeVec, Value = apply(MAEMat, MARGIN = 1, mean),
upp = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
low = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.1)}))
MAEMat = as.matrix(TempDf[17:32,])
MAEDf <- rbind(MAEDf, data.frame(Model = 'PCL', Size = SizeVec, Value = apply(MAEMat, MARGIN = 1, mean),
upp = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
low = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.1)})))
p1 <- ggplot(MAEDf, aes(x = Size, y = Value, group = Model)) +
geom_ribbon(data = MAEDf %>% filter(Model == "MNL"), aes(ymin = low, ymax = upp), alpha = .1) +
geom_ribbon(data = MAEDf %>% filter(Model == "PCL"), aes(ymin = low, ymax = upp), alpha = .1) +
geom_line(aes(color = Model), size = 1.5) + scale_colour_brewer(palette="Set2") + ylab('MAE') +
xlab(bquote(log[10]~'(Sample Size)'))+ theme_bw() + theme(text = element_text(size=15))
library(ggplot2)
library(dplyr)
library(wesanderson)
library(gridExtra)
p1 <- ggplot(MAEDf, aes(x = Size, y = Value, group = Model)) +
geom_ribbon(data = MAEDf %>% filter(Model == "MNL"), aes(ymin = low, ymax = upp), alpha = .1) +
geom_ribbon(data = MAEDf %>% filter(Model == "PCL"), aes(ymin = low, ymax = upp), alpha = .1) +
geom_line(aes(color = Model), size = 1.5) + scale_colour_brewer(palette="Set2") + ylab('MAE') +
xlab(bquote(log[10]~'(Sample Size)'))+ theme_bw() + theme(text = element_text(size=15))
p1
View(p1)
# MAPE
MAPEMat = as.matrix(TempDf[33:48,])
MAPEDf <- data.frame(Model = 'MNL', Size = SizeVec, Value = apply(MAPEMat, MARGIN = 1, mean),
upp = apply(MAPEMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
low = apply(MAPEMat, MARGIN = 1, function(x){quantile(x, 0.1)}))
MAPEMat = as.matrix(TempDf[49:64,])
MAPEDf <- rbind(MAPEDf, data.frame(Model = 'PCL', Size = SizeVec, Value = apply(MAPEMat, MARGIN = 1, mean),
upp = apply(MAPEMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
low = apply(MAPEMat, MARGIN = 1, function(x){quantile(x, 0.1)})))
p2 <- ggplot(MAPEDf, aes(x = Size, y = Value, group = Model)) +
geom_ribbon(data = MAPEDf %>% filter(Model == "MNL"), aes(ymin = low, ymax = upp), alpha = .1) +
geom_ribbon(data = MAPEDf %>% filter(Model == "PCL"), aes(ymin = low, ymax = upp), alpha = .1) +
geom_line(aes(color = Model), size = 1.5) + scale_colour_brewer(palette="Set2") + ylab('MAPE') +
xlab(bquote(log[10]~'(Sample Size)'))+ theme_bw() + theme(text = element_text(size=15))
# Out-of-sample log-likelihood
LlhMat = as.matrix(TempDf[65:80,])
LlhDf <- data.frame(Model = 'MNL', Size = SizeVec, Value = apply(LlhMat, MARGIN = 1, mean),
upp = apply(LlhMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
low = apply(LlhMat, MARGIN = 1, function(x){quantile(x, 0.1)}))
LlhMat = as.matrix(TempDf[81:96,])
LlhDf <- rbind(LlhDf, data.frame(Model = 'PCL', Size = SizeVec, Value = apply(LlhMat, MARGIN = 1, mean),
upp = apply(LlhMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
low = apply(LlhMat, MARGIN = 1, function(x){quantile(x, 0.1)})))
p3 <- ggplot(LlhDf, aes(x = Size, y = Value, group = Model), size = 1.5) +
geom_ribbon(data = LlhDf %>% filter(Model == "MNL"), aes(ymin = low, ymax = upp), alpha = .1) +
geom_ribbon(data = LlhDf %>% filter(Model == "PCL"), aes(ymin = low, ymax = upp), alpha = .1) +
geom_line(aes(color = Model), size = 1.5) + scale_colour_brewer(palette="Set2") + ylab('Out-of-sample log-likelihood') +
xlab(bquote(log[10]~'(Sample Size)'))+ theme_bw() + theme(text = element_text(size=15))
grid.arrange(p1, p2, p3, nrow = 1)
# MAE
MAEMat = as.matrix(TempDf[1:16,])
MAEDf <- data.frame(Model = 'MNL', Size = SizeVec, Value = apply(MAEMat, MARGIN = 1, mean),
upp = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
low = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.1)}))
MAEMat = as.matrix(TempDf[17:32,])
MAEDf <- rbind(MAEDf, data.frame(Model = 'PCL', Size = SizeVec, Value = apply(MAEMat, MARGIN = 1, mean),
upp = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
low = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.1)})))
p1 <- ggplot(MAEDf, aes(x = Size, y = Value, group = Model)) +
geom_line(aes(color = Model, linetype = Model), size = 1.5) +
scale_colour_brewer(palette="Set2") +
ylab('MAE') +
xlab(bquote(log[10]~'(Sample Size)'))+ theme_bw() + theme(text = element_text(size=15))
p1
# MAPE
MAPEMat = as.matrix(TempDf[33:48,])
MAPEDf <- data.frame(Model = 'MNL', Size = SizeVec, Value = apply(MAPEMat, MARGIN = 1, mean),
upp = apply(MAPEMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
low = apply(MAPEMat, MARGIN = 1, function(x){quantile(x, 0.1)}))
MAPEMat = as.matrix(TempDf[49:64,])
MAPEDf <- rbind(MAPEDf, data.frame(Model = 'PCL', Size = SizeVec, Value = apply(MAPEMat, MARGIN = 1, mean),
upp = apply(MAPEMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
low = apply(MAPEMat, MARGIN = 1, function(x){quantile(x, 0.1)})))
p2 <- ggplot(MAPEDf, aes(x = Size, y = Value, group = Model)) +
geom_line(aes(color = Model, linetype = Model), size = 1.5) +
scale_colour_brewer(palette="Set2") + ylab('MAPE') +
xlab(bquote(log[10]~'(Sample Size)'))+ theme_bw() + theme(text = element_text(size=15))
# Out-of-sample log-likelihood
LlhMat = as.matrix(TempDf[65:80,])
LlhDf <- data.frame(Model = 'MNL', Size = SizeVec, Value = apply(LlhMat, MARGIN = 1, mean),
upp = apply(LlhMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
low = apply(LlhMat, MARGIN = 1, function(x){quantile(x, 0.1)}))
LlhMat = as.matrix(TempDf[81:96,])
LlhDf <- rbind(LlhDf, data.frame(Model = 'PCL', Size = SizeVec, Value = apply(LlhMat, MARGIN = 1, mean),
upp = apply(LlhMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
low = apply(LlhMat, MARGIN = 1, function(x){quantile(x, 0.1)})))
p3 <- ggplot(LlhDf, aes(x = Size, y = Value, group = Model), size = 1.5) +
geom_line(aes(color = Model, linetype = Model), size = 1.5) +
scale_colour_brewer(palette="Set2") + ylab('Out-of-sample log-likelihood') +
xlab(bquote(log[10]~'(Sample Size)'))+ theme_bw() + theme(text = element_text(size=15))
grid.arrange(p1, p2, p3, nrow = 1)
# MAE
MAEMat = as.matrix(TempDf[1:16,])
MAEDf <- data.frame(Model = 'MNL', Size = SizeVec, Value = apply(MAEMat, MARGIN = 1, mean),
Std = apply(MAEMat, MARGIN = 1, sd))
MAEMat = as.matrix(TempDf[17:32,])
MAEDf <- rbind(MAEDf, data.frame(Model = 'PCL', Size = SizeVec, Value = apply(MAEMat, MARGIN = 1, mean),
Std = apply(MAEMat, MARGIN = 1, sd)))
p1 <- ggplot(MAEDf, aes(x = Size, y = Value, group = Model)) +
geom_errorbar(aes(color = Model, ymin = Value - Std, ymax = Value + Std, linetype = Model), width = 0,
position = position_dodge(width = 0.05), size = 0.8) +
geom_line(aes(color = Model, linetype = Model), size = 1.5, position = position_dodge(width = 0.1)) +
scale_colour_brewer(palette="Set2") + ylab('MAE') +
xlab(bquote(log[10]~'(Sample Size)'))+ theme_bw() + theme(text = element_text(size=15))
p1
# MAPE
MAPEMat = as.matrix(TempDf[33:48,])
MAPEDf <- data.frame(Model = 'MNL', Size = SizeVec, Value = apply(MAPEMat, MARGIN = 1, mean),
Std = apply(MAPEMat, MARGIN = 1, sd))
MAPEMat = as.matrix(TempDf[49:64,])
MAPEDf <- rbind(MAPEDf, data.frame(Model = 'PCL', Size = SizeVec, Value = apply(MAPEMat, MARGIN = 1, mean),
Std = apply(MAPEMat, MARGIN = 1, sd)))
p2 <- ggplot(MAPEDf, aes(x = Size, y = Value, group = Model)) +
geom_errorbar(aes(color = Model, ymin = Value - Std, ymax = Value + Std, linetype = Model), width = 0,
position = position_dodge(width = 0.05), size = 0.8) +
geom_line(aes(color = Model, linetype = Model), size = 1.5, position = position_dodge(width = 0.1)) +
scale_colour_brewer(palette="Set2") + ylab('MAE') +
xlab(bquote(log[10]~'(Sample Size)'))+ theme_bw() + theme(text = element_text(size=15))
p2
# Out-of-sample log-likelihood
LlhMat = as.matrix(TempDf[65:80,])
LlhDf <- data.frame(Model = 'MNL', Size = SizeVec, Value = apply(LlhMat, MARGIN = 1, mean),
Std = apply(LlhMat, MARGIN = 1, sd))
LlhMat = as.matrix(TempDf[81:96,])
LlhDf <- rbind(LlhDf, data.frame(Model = 'PCL', Size = SizeVec, Value = apply(LlhMat, MARGIN = 1, mean),
Std = apply(LlhMat, MARGIN = 1, sd)))
p3 <- ggplot(LlhDf, aes(x = Size, y = Value, group = Model)) +
geom_errorbar(aes(color = Model, ymin = Value - Std, ymax = Value + Std, linetype = Model), width = 0,
position = position_dodge(width = 0.05), size = 0.8) +
geom_line(aes(color = Model, linetype = Model), size = 1.5, position = position_dodge(width = 0.1)) +
scale_colour_brewer(palette="Set2") + ylab('MAE') +
xlab(bquote(log[10]~'(Sample Size)'))+ theme_bw() + theme(text = element_text(size=15))
p3
grid.arrange(p1, p2, p3, nrow = 1)
View(MAEDf)
rep('PCL',16)
MAEDf <- rbind(MAEDf, data.frame(Model = c(rep('MNL',16), rep('PCL',16)),
Metric = 'MAE',
Size = SizeVec, Value = apply(MAEMat, MARGIN = 1, mean),
upp = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
low = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.1)})),
std = apply(MAEMat, MARGIN = 1, sd))
MAEDf <- data.frame(Model = c(rep('MNL',16), rep('PCL',16)),
Metric = 'MAE',
Size = SizeVec, Value = apply(MAEMat, MARGIN = 1, mean),
upp = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
low = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.1)})),
std = apply(MAEMat, MARGIN = 1, sd)
c(rep('MNL',16), rep('PCL',16)
)
MAEDf <- data.frame(Model = c(rep('MNL',16), rep('PCL',16)),
Metric = 'MAE',
Size = SizeVec, Value = apply(MAEMat, MARGIN = 1, mean),
upp = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
low = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.1)})),
std = apply(MAEMat, MARGIN = 1, sd)
MAEDf <- data.frame(Model = c(rep('MNL',16), rep('PCL',16)),
Metric = 'MAE',
Size = SizeVec, Value = apply(MAEMat, MARGIN = 1, mean),
upp = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
low = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.1)}),
std = apply(MAEMat, MARGIN = 1, sd))
MAEDf <- data.frame(Model = c(rep('MNL',16), rep('PCL',16)),
Metric = 'MAE',
Size = SizeVec,
Mean = apply(MAEMat, MARGIN = 1, mean),
qtl_90 = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
qtl_10 = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.1)}),
std = apply(MAEMat, MARGIN = 1, sd))
View(MAEDf)
# Produce the excel file huseyin
MAEMat = as.matrix(TempDf[1:32,])
MAEDf <- data.frame(Model = c(rep('MNL',16), rep('PCL',16)),
Metric = 'MAE',
Size = SizeVec,
Mean = apply(MAEMat, MARGIN = 1, mean),
qtl_90 = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
qtl_10 = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.1)}),
std = apply(MAEMat, MARGIN = 1, sd))
# Produce the excel file huseyin
MAEMat = as.matrix(TempDf[1:32,])
MAEDf2 <- data.frame(Model = c(rep('MNL',16), rep('PCL',16)),
Metric = 'MAE',
Size = SizeVec,
Mean = apply(MAEMat, MARGIN = 1, mean),
qtl_90 = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
qtl_10 = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.1)}),
std = apply(MAEMat, MARGIN = 1, sd))
AEMat = as.matrix(TempDf[33:64,])
MAPEDf2 <- data.frame(Model = c(rep('MNL',16), rep('PCL',16)),
Metric = 'MAPE',
Size = SizeVec,
Mean = apply(MAEMat, MARGIN = 1, mean),
qtl_90 = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
qtl_10 = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.1)}),
std = apply(MAEMat, MARGIN = 1, sd))
AEMat = as.matrix(TempDf[65:96,])
LlhDf2 <- data.frame(Model = c(rep('MNL',16), rep('PCL',16)),
Metric = 'Log-likelihood',
Size = SizeVec,
Mean = apply(MAEMat, MARGIN = 1, mean),
qtl_90 = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
qtl_10 = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.1)}),
std = apply(MAEMat, MARGIN = 1, sd))
# Produce the excel file huseyin
MAEMat = as.matrix(TempDf[1:32,])
MAEDf2 <- data.frame(Model = c(rep('MNL',16), rep('PCL',16)),
Metric = 'MAE',
Size = SizeVec,
Mean = apply(MAEMat, MARGIN = 1, mean),
qtl_90 = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
qtl_10 = apply(MAEMat, MARGIN = 1, function(x){quantile(x, 0.1)}),
std = apply(MAEMat, MARGIN = 1, sd))
MAPEMat = as.matrix(TempDf[33:64,])
MAPEDf2 <- data.frame(Model = c(rep('MNL',16), rep('PCL',16)),
Metric = 'MAPE',
Size = SizeVec,
Mean = apply(MAPEMat, MARGIN = 1, mean),
qtl_90 = apply(MAPEMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
qtl_10 = apply(MAPEMat, MARGIN = 1, function(x){quantile(x, 0.1)}),
std = apply(MAPEMat, MARGIN = 1, sd))
LlhMat = as.matrix(TempDf[65:96,])
LlhDf2 <- data.frame(Model = c(rep('MNL',16), rep('PCL',16)),
Metric = 'Log-likelihood',
Size = SizeVec,
Mean = apply(LlhMat, MARGIN = 1, mean),
qtl_90 = apply(LlhMat, MARGIN = 1, function(x){quantile(x, 0.9)}),
qtl_10 = apply(LlhMat, MARGIN = 1, function(x){quantile(x, 0.1)}),
std = apply(LlhMat, MARGIN = 1, sd))
resultDf <- rbind(MAEDf2, MAPEDf2, LlhDf2)
View(resultDf)
?csv.write
?write.csv
write.csv("Results/ResultSummary.csv")
write.csv(resultDf, "Results/ResultSummary.csv")
