Created
December 7, 2020 10:49
-
-
Save geotheory/48a649b2b9dbb3d643fc83c6ea8339bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(tidyverse) | |
mm_ratio = function(x) mean(x) / median(x) | |
x = map(10^seq(2,6,length.out = 200), ~ list(unif = runif(.x), exp = rexp(.x), log = rlnorm(.x))) | |
d = x %>% map_df(~ tibble(n = length(.x$unif), | |
unif = mm_ratio(.x$unif), | |
exp = mm_ratio(.x$exp), | |
log = mm_ratio(.x$log))) | |
ds = d %>% pivot_longer(-n) %>% | |
filter(n > 100000) %>% | |
group_by(name) %>% summarise(value = mean(value)) | |
d %>% pivot_longer(-n) %>% | |
ggplot(aes(n, value, col = name)) + | |
geom_point(size = .5, show.legend = FALSE) + geom_line(size = .3) + | |
geom_text(data = ds, aes(x = 1e6, y = value, label = round(value,3)), hjust = 0, nudge_x = 0.02, show.legend = FALSE) + | |
scale_x_log10(labels = scales::comma, limits = c(100, 1300000)) + | |
labs(x = 'Array size', y = 'Ratio', title = 'Mean / Median ratio', col = 'Distribution') + | |
theme(legend.position = 'top') + | |
guides(colour = guide_legend(override.aes = list(size = 4)))+ | |
theme(legend.key=element_rect(fill=NA)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment