Created
December 30, 2019 19:48
-
-
Save statwonk/74a09b0abc0248065e850ffe24d7dafa to your computer and use it in GitHub Desktop.
Measuring retweets, for fun!
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
library(fitdistrplus) | |
library(countreg) | |
library(tidyverse) | |
library(rtweet) | |
get_timeline("statwonk", n = 1e4) %>% | |
filter(!is_retweet) %>% | |
pull(retweet_count) -> my_retweets | |
# I know a priori it's negbin, | |
# but let's use a rootogram to check | |
# for fun. :-) | |
MASS::glm.nb(my_retweets ~ 1) %>% | |
rootogram() | |
my_retweets %>% | |
fitdist(distr = "nbinom") %>% | |
coef() %>% | |
as.list() %>% | |
c(list(n = 2e3)) %>% | |
{ do.call(rnbinom, .) } %>% # splat params | |
barplot(main = "2k simulated tweets", ylab = "Retweets") | |
max(my_retweets) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment