Commit bdafd5db authored by kevin's avatar kevin

figures update

parent b0dd68da
...@@ -564,15 +564,15 @@ compute_summary_measures <- function(df) { ...@@ -564,15 +564,15 @@ compute_summary_measures <- function(df) {
summarize( summarize(
RMSE = mean((GOSE - prediction)^2, na.rm = TRUE) %>% sqrt, RMSE = mean((GOSE - prediction)^2, na.rm = TRUE) %>% sqrt,
MAE = mean(abs(GOSE - prediction), na.rm = TRUE), MAE = mean(abs(GOSE - prediction), na.rm = TRUE),
Bias = mean(prediction, na.rm = TRUE) - mean(GOSE, na.rm = TRUE), bias = mean(prediction, na.rm = TRUE) - mean(GOSE, na.rm = TRUE),
`Bias'` = mean(prediction > GOSE, na.rm = TRUE) - mean(prediction < GOSE, na.rm = TRUE) `d-bias` = mean(prediction > GOSE, na.rm = TRUE) - mean(prediction < GOSE, na.rm = TRUE)
) %>% ) %>%
ungroup %>% ungroup %>%
gather(error, value, -model, -fold) %>% gather(error, value, -model, -fold) %>%
mutate( mutate(
error = factor(error, c( error = factor(error, c(
"Bias", "bias",
"Bias'", "d-bias",
"MAE", "MAE",
"RMSE" "RMSE"
)) ))
...@@ -663,7 +663,7 @@ The GOSe scale is restricted to 3+ since the imputation is conditional on ...@@ -663,7 +663,7 @@ The GOSe scale is restricted to 3+ since the imputation is conditional on
an observed GOSe larger than 1 (deaths are known and no imputation necessary) an observed GOSe larger than 1 (deaths are known and no imputation necessary)
and no GOSe 2 was observed. and no GOSe 2 was observed.
```{r confusion-matrix-locf, warning=FALSE, message=FALSE, echo=FALSE, fig.cap="Confusion matrices on LOCF subset.", fig.height=6, fig.width=6} ```{r confusion-matrix-locf, warning=FALSE, message=FALSE, echo=FALSE, fig.cap="Confusion matrices on LOCF subset.", fig.height=3, fig.width=6}
plot_confusion_matrices <- function(df_predictions, models, nrow = 2, legendpos, scriptsize) { plot_confusion_matrices <- function(df_predictions, models, nrow = 2, legendpos, scriptsize) {
...@@ -686,7 +686,8 @@ plot_confusion_matrices <- function(df_predictions, models, nrow = 2, legendpos, ...@@ -686,7 +686,8 @@ plot_confusion_matrices <- function(df_predictions, models, nrow = 2, legendpos,
ungroup %>% ungroup %>%
mutate(model = factor(model, models)) mutate(model = factor(model, models))
p_cnf_mtrx_raw <- df_average_confusion_matrices %>% # p_cnf_mtrx_raw <-
df_average_confusion_matrices %>%
ggplot(aes(`Observed GOSE`, `Predicted GOSE`, fill = n)) + ggplot(aes(`Observed GOSE`, `Predicted GOSE`, fill = n)) +
geom_raster(fill = "white") + geom_raster(fill = "white") +
geom_text(aes( geom_text(aes(
...@@ -710,28 +711,28 @@ plot_confusion_matrices <- function(df_predictions, models, nrow = 2, legendpos, ...@@ -710,28 +711,28 @@ plot_confusion_matrices <- function(df_predictions, models, nrow = 2, legendpos,
facet_wrap(~model, nrow = nrow) + facet_wrap(~model, nrow = nrow) +
ggtitle("Average confusion matrix across folds (absolute counts)") ggtitle("Average confusion matrix across folds (absolute counts)")
p_cnf_mtrx_colnrm <- df_average_confusion_matrices %>% # p_cnf_mtrx_colnrm <- df_average_confusion_matrices %>%
group_by(model, `Observed GOSE`) %>% # group_by(model, `Observed GOSE`) %>%
mutate( # mutate(
`fraction (column)` = n / sum(n), # `fraction (column)` = n / sum(n),
`fraction (column)` = ifelse(is.nan(`fraction (column)`), 0, `fraction (column)`) # `fraction (column)` = ifelse(is.nan(`fraction (column)`), 0, `fraction (column)`)
) %>% # ) %>%
ggplot(aes(`Observed GOSE`, `Predicted GOSE`, fill = `fraction (column)`)) + # ggplot(aes(`Observed GOSE`, `Predicted GOSE`, fill = `fraction (column)`)) +
geom_raster() + # geom_raster() +
geom_hline(yintercept = c(2, 4, 6) + .5, color = "black") + # geom_hline(yintercept = c(2, 4, 6) + .5, color = "black") +
geom_vline(xintercept = c(2, 4, 6) + .5, color = "black") + # geom_vline(xintercept = c(2, 4, 6) + .5, color = "black") +
scale_fill_gradient("", low = "white", high = "black", limits = c(0, 1)) + # scale_fill_gradient("", low = "white", high = "black", limits = c(0, 1)) +
coord_fixed(expand = FALSE) + # coord_fixed(expand = FALSE) +
labs(x = "observed GOSe", y = "imputed GOSe", fill = "") + # labs(x = "observed GOSe", y = "imputed GOSe", fill = "") +
theme_bw() + # theme_bw() +
theme( # theme(
panel.grid = element_blank(), # panel.grid = element_blank(),
legend.position = legendpos # legend.position = legendpos
) + # ) +
facet_wrap(~model, nrow = nrow) + # facet_wrap(~model, nrow = nrow) +
ggtitle("Average confusion matrix across folds (column fraction)") # ggtitle("Average confusion matrix across folds (column fraction)")
cowplot::plot_grid(p_cnf_mtrx_raw, p_cnf_mtrx_colnrm, ncol = 1, align = "h") # cowplot::plot_grid(p_cnf_mtrx_raw, p_cnf_mtrx_colnrm, ncol = 1, align = "h")
} }
plot_confusion_matrices( plot_confusion_matrices(
...@@ -743,8 +744,8 @@ plot_confusion_matrices( ...@@ -743,8 +744,8 @@ plot_confusion_matrices(
scriptsize = 2.5 scriptsize = 2.5
) )
ggsave(filename = "confusion_matrices_locf.pdf", width = 6, height = 6) ggsave(filename = "confusion_matrices_locf.pdf", width = 6, height = 3)
ggsave(filename = "confusion_matrices_locf.png", width = 6, height = 6) ggsave(filename = "confusion_matrices_locf.png", width = 6, height = 3)
``` ```
The absolute-count confusion matrices show that most imputed values are The absolute-count confusion matrices show that most imputed values are
...@@ -772,8 +773,8 @@ plot_summary_measures_cond <- function(df_predictions, models, label) { ...@@ -772,8 +773,8 @@ plot_summary_measures_cond <- function(df_predictions, models, label) {
summarize( summarize(
RMSE = mean((GOSE - prediction)^2, na.rm = TRUE) %>% sqrt, RMSE = mean((GOSE - prediction)^2, na.rm = TRUE) %>% sqrt,
MAE = mean(abs(GOSE - prediction), na.rm = TRUE), MAE = mean(abs(GOSE - prediction), na.rm = TRUE),
Bias = mean(prediction, na.rm = TRUE) - mean(GOSE, na.rm = TRUE), bias = mean(prediction, na.rm = TRUE) - mean(GOSE, na.rm = TRUE),
`Bias'` = mean(prediction > GOSE, na.rm = TRUE) - mean(prediction < GOSE, na.rm = TRUE) `d-bias` = mean(prediction > GOSE, na.rm = TRUE) - mean(prediction < GOSE, na.rm = TRUE)
) %>% ) %>%
gather(error, value, -model, -GOSE, -fold) %>% gather(error, value, -model, -GOSE, -fold) %>%
group_by(GOSE, model, error, fold) %>% group_by(GOSE, model, error, fold) %>%
...@@ -789,20 +790,24 @@ plot_summary_measures_cond <- function(df_predictions, models, label) { ...@@ -789,20 +790,24 @@ plot_summary_measures_cond <- function(df_predictions, models, label) {
mutate( mutate(
model = factor(model, models), model = factor(model, models),
error = factor(error, c( error = factor(error, c(
"Bias", "bias",
"Bias'", "d-bias",
"MAE", "MAE",
"RMSE" "RMSE"
)) ))
) %>% ) %>%
ggplot(aes(GOSE, color = model)) + ggplot(aes(GOSE, color = model)) +
geom_hline(yintercept = 0, color = "black") + geom_hline(yintercept = 0, color = "black") +
geom_line(aes(y = mean)) + geom_line(aes(y = mean), alpha = .5) +
geom_point(aes(y = mean), size = .3,
position = position_dodge(.2)) +
geom_errorbar(aes(ymin = mean - 1.96*se, ymax = mean + 1.96*se), geom_errorbar(aes(ymin = mean - 1.96*se, ymax = mean + 1.96*se),
width = .2, width = .33,
position = position_dodge(.33), size = .5,
size = 1 position = position_dodge(.2)
) + ) +
geom_point(aes(y = mean),
position = position_dodge(.2)) +
xlab("observed GOSe") + xlab("observed GOSe") +
facet_wrap(~error, nrow = 1) + facet_wrap(~error, nrow = 1) +
scale_y_continuous(name = "", breaks = seq(-2, 8, .5)) + scale_y_continuous(name = "", breaks = seq(-2, 8, .5)) +
...@@ -824,7 +829,7 @@ plot_summary_measures_cond( ...@@ -824,7 +829,7 @@ plot_summary_measures_cond(
) )
ggsave(filename = "errors_stratified_locf.pdf", width = 6, height = 3.5) ggsave(filename = "errors_stratified_locf.pdf", width = 6, height = 3.5)
ggsave(filename = "errors_stratified_locf.png", width = 6, height = 3.5) ggsave(filename = "errors_stratified_locf.png", width = 6, height = 3.5, scale = 1.25)
``` ```
Just as with the overall performance, differences are most pronounced in terms Just as with the overall performance, differences are most pronounced in terms
...@@ -879,8 +884,8 @@ plot_confusion_matrices( ...@@ -879,8 +884,8 @@ plot_confusion_matrices(
scriptsize = 3 scriptsize = 3
) )
ggsave(filename = "confusion_matrices_all.pdf", width = 6, height = 6) ggsave(filename = "confusion_matrices_all.pdf", width = 6, height = 3)
ggsave(filename = "confusion_matrices_all.png", width = 6, height = 6) ggsave(filename = "confusion_matrices_all.png", width = 6, height = 3)
``` ```
...@@ -893,7 +898,7 @@ plot_summary_measures_cond( ...@@ -893,7 +898,7 @@ plot_summary_measures_cond(
) )
ggsave(filename = "imputation_error.pdf", width = 6, height = 3.5) ggsave(filename = "imputation_error.pdf", width = 6, height = 3.5)
ggsave(filename = "imputation_error.png", width = 6, height = 3.5) ggsave(filename = "imputation_error.png", width = 6, height = 3.5, scale = 1.25)
``` ```
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment