Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created September 28, 2024 21:38
Show Gist options
  • Save abikoushi/fd9b5976e92e4c8053106325d4d28157 to your computer and use it in GitHub Desktop.
Save abikoushi/fd9b5976e92e4c8053106325d4d28157 to your computer and use it in GitHub Desktop.
Plot tweedie distribution
library(tweedie)
library(dplyr)
library(ggplot2)
library(ggh4x)
pow <- c(1.01,1.05,1.3,1.9)
phi <- c(0.2,0.5,1,3)
mu <- c(0.1,0.3,2)
dens <- expand.grid(y=y,power=pow,mu=mu,phi=phi) %>%
group_by(power) %>%
mutate(density = dtweedie(y=y, power = first(power), mu=mu, phi=phi)) %>%
ungroup()
ggplot(dens, aes(x=y, y=density))+
geom_area(alpha=0.3,colour="black")+
facet_grid2(mu+power~phi, labeller = label_both, scales = "free_y")+
theme_classic(16)+theme(strip.text.y = element_text(angle = 0))
ggsave("tweedie.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment