Skip to content

Commit

Permalink
Book graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
chjackson committed Nov 4, 2023
1 parent 810df16 commit adec4d8
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions inst/book_misc/he_graphs.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ dlogitnorm <- function(x, mu, sd){

pdat <- data.frame(x = seq(0, 1, by=0.01)) %>%
mutate(dbet = dbeta(x, bet[["shape1"]], bet[["shape2"]]),
dln = plogitnorm(x, qlogis(0.4),
(qlogis(0.6) - qlogis(0.2))/(2*qnorm(0.975))))
dln = dlogitnorm(x, qlogis(0.4),
(qlogis(0.6) - qlogis(0.2))/(2*qnorm(0.975)))) %>%
pivot_longer(cols = c("dbet", "dln"), names_to="dist", values_to = "dens") %>%
mutate(dist = fct_recode(dist, "Beta(8.9, 13.1)"="dbet", "Logit-normal(-0.4,0.46)"="dln"))

green <- viridis(5)[4]
purple <- viridis(5)[2]
pdf("~/work/voibook/voibook/Figures/02-healthecon/elic_compare.pdf", width=6, height=4)
ggplot(pdat, aes(x=x, y=dbet)) +
geom_line(lwd=2, col=green) +
geom_line(aes(y=dln), col=purple, lwd=2) +
geom_text(aes(x=0.55, y=3), label="Beta(8.9, 13.1)", col=green, hjust=0) +
geom_text(aes(x=0.55, y=2.6), label="Logit-normal(-0.4,0.46)", col=purple, hjust=0) +
pdf("~/work/voibook/voibook/chapters/chapter01_modelling/elic_compare.pdf", width=6, height=4)
ggplot(pdat, aes(x=x, y=dens, col=dist, linetype=dist)) +
geom_line(lwd=2) +
scale_color_manual(name = "", values = c(green, purple)) +
scale_linetype_manual(name = "", values=c(1, 3)) +
theme_bw() +
theme(legend.position = c(0.8, 0.8) ) +
xlab(expression(italic(p))) + ylab("Probability density") +
scale_x_continuous(breaks = c(0, 0.2, 0.4, 0.6, 0.8, 1))
dev.off()

0 comments on commit adec4d8

Please sign in to comment.