g <- \(x) 0.55 * log(x) / log(4)
shared <- \(x) 0.2 + g(x)
int_labels <- c("No interaction", "Separate curves (current)", "Sum-to-zero deviations",
"Penalised deviations", "Horizon as categories")
lv <- \(d) mutate(d, p = factor(p, int_labels))
# models A and B: level and slope multiplier per specification
ab <- tibble(
p = rep(int_labels, each = 2), model = rep(c("A", "B"), 5),
level = c(-0.10, 0.15, -0.10, 0.15, -0.12, 0.12, -0.08, 0.12, -0.08, 0.12),
slope = c(1, 1, 0.5, 1.6, 0.5, 1.5, 0.75, 1.25, 0.75, 1.25)
)
curve_ab <- crossing(ab, x = hf) |> mutate(y = 0.2 + level + slope * g(x))
point_ab <- crossing(ab, x = h) |> mutate(y = 0.2 + level + slope * g(x))
# model C: horizon 1 only
c_obs <- 0.8
pivot <- c(x = 2.45, y = shared(2.45))
c_fun <- list(
`No interaction` = \(x) c_obs + g(x),
`Separate curves (current)` = \(x) c_obs + (pivot[["y"]] - c_obs) * (x - 1) / (pivot[["x"]] - 1),
`Penalised deviations` = \(x) c_obs + g(x),
`Horizon as categories` = \(x) c_obs + g(x)
)
c_line <- imap_dfr(c_fun[1:3], \(f, p) tibble(p = p, x = hf, y = f(hf)))
c_pts <- imap_dfr(c_fun, \(f, p) tibble(p = p, x = h[-1], y = f(h[-1])))
ggplot(mapping = aes(x, y)) +
geom_rect(data = lv(tibble(p = int_labels[3])), inherit.aes = FALSE,
aes(xmin = 1.15, xmax = 4.15, ymin = -Inf, ymax = Inf),
fill = "grey85", alpha = 0.6) +
geom_line(data = lv(crossing(p = int_labels[c(1, 3, 4)], x = hf) |> mutate(y = shared(x))),
colour = "firebrick", linewidth = 1.2) +
geom_point(data = lv(tibble(p = int_labels[5], x = h, y = shared(h))),
colour = "firebrick", size = 3, shape = 15) +
geom_line(data = lv(filter(curve_ab, p != int_labels[5])), aes(group = model), colour = "grey30") +
geom_point(data = lv(point_ab), aes(shape = model), colour = "grey30", size = 2) +
geom_line(data = lv(c_line), colour = "grey30", linetype = "dashed") +
geom_point(data = lv(c_pts), colour = "grey30", shape = 1, size = 2.5) +
geom_point(data = lv(tibble(p = int_labels, x = 1, y = c_obs)), colour = "grey30", size = 3) +
facet_wrap(~ p, ncol = 3, labeller = label_wrap_gen(25)) +
scale_shape_manual(values = c(A = 16, B = 17), guide = "none") +
scale_x_continuous(breaks = 1:4) +
coord_cartesian(ylim = c(-0.1, 1.45)) +
labs(x = "Horizon (weeks)", y = "Log LWIS (schematic)") +
theme_minimal() +
theme(axis.text.y = element_blank(), panel.grid.minor = element_blank(),
strip.text = element_text(hjust = 0))