temp-bikes/plotscripts/03-predictive-distribution.R

library(ggplot2)
library(devtools)
library(data.table)
load_all()




df <- data.table(cbind(bikes_atom, group = rep(1:10, each = 53)))
a <- seq(min(df$t), max(df$t), 1) # Used for ticks and labels
ggplot(df, aes(y = pmean, x = t, color = method)) +
    geom_line() +
    geom_line(
        aes(y = ytrue, x = t),
        color = "black"
    ) +
    facet_wrap( ~ group, ncol = 1, scales = "free") +
    labs(
        title = "Predictive means, the truth is black",
        x = "Time",
        y = "pmean"
    ) +
    scale_x_continuous(breaks = a[a %% 5 == 0], minor_breaks = seq(min(df$t), max(df$t), 1)) +
    theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))

################################################################
### Log predictive densities for all models in the same plot ###
################################################################

lpdensplot_all_1 <- ggplot(df[group <= 5], aes(y = lpdens, x = t, col = method)) +
    geom_line() +
    facet_wrap( ~ group, ncol = 1, scales = "free") +
    labs(
        title = "Log predictive densities",
        x = "Time",
        y = "lpdens"
    ) +
    scale_x_continuous(breaks = a[a %% 5 == 0], minor_breaks = seq(min(df$t), max(df$t), 1)) +
    theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))

lpdensplot_all_2 <- ggplot(df[group > 5], aes(y = lpdens, x = t, col = method)) +
    geom_line() +
    facet_wrap( ~ group, ncol = 1, scales = "free") +
    labs(
        title = "Log predictive densities",
        x = "Time",
        y = "lpdens"
    ) +
    scale_x_continuous(breaks = a[a %% 5 == 0], minor_breaks = seq(min(df$t), max(df$t), 1)) +
    theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))

ggsave(
    "temp-bikes/plots/lpdens_all_1.pdf", 
    lpdensplot_all_1,
    width = 10,
    height = 20,
    dpi = 300,
    units = "in",
    device = "pdf")
ggsave(
    "temp-bikes/plots/lpdens_all_2.pdf", 
    lpdensplot_all_2,
    width = 10,
    height = 20,
    dpi = 300,
    units = "in",
    device = "pdf")
ooelrich/oscbvar documentation built on Sept. 8, 2021, 3:31 p.m.