Skip to content

David-Salazar/ggtails

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ggtails

The goal of ggtails is to make the use of fat tails specific plots as easy as possible within the usual ggplot2 framework. To do so, I took the computational steps in the great evir package and turned them into ggplot2 stats.

Check this blogpost for an intuitive explanation of these types of plots.

Installation

# install.packages("devtools")
devtools::install_github("David-Salazar/ggtails")

Example

For example, you can create a zipf plot for different random variables in the same way as would use stat_qq()

library(ggtails)
library(tidyverse)

gaussian <- rnorm(10000)
lognormal <- rlnorm(10000)
exponential <- rexp(10000)
pareto <- 1/(runif(10000))^(1/1.16) # inverse transform sampling

tibble(sim = 1:10000, lognormal, exponential, pareto) %>% 
  pivot_longer(-sim, names_to = "random_variable", values_to = "value") %>% 
  ggplot(aes(sample = value, color = random_variable)) +
  stat_zipf(alpha = 0.1) +
  scale_x_log10() +
  scale_y_log10() +
  theme_minimal() +
  labs(title = "Zipf plot in ggplot2 workflow",
       x = "Log(x)",
       y = "Log(Survival(x))")

In the same way, we can create a mean excess plot:

tibble(sim = 1:10000, gaussian, lognormal, exponential, pareto) %>% 
  pivot_longer(-sim, names_to = "random_variable", values_to = "value") %>% 
  ggplot(aes(sample = value)) +
  stat_mean_excess(alpha = 0.1) +
  facet_wrap(~random_variable, scales = "free") +
  theme_minimal() +
  labs(title = "Mean Excess plot works with facetting!")

Finally, we can perform a visual examination of fat-tailedness by examining the convergence of moments with the max-to-sum plots. For finite moments, the ratio should converge to 0.

tibble(sim = 1:10000, gaussian, lognormal, exponential, pareto) %>% 
  pivot_longer(-sim, names_to = "random_variable", values_to = "value") %>% 
  ggplot(aes(sample = value)) +
  stat_max_sum_ratio_plot(p = 4) +
  facet_wrap(~random_variable) +
  theme_minimal()

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages