Skip to content

Instantly share code, notes, and snippets.

@statwonk
Created December 30, 2019 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save statwonk/74a09b0abc0248065e850ffe24d7dafa to your computer and use it in GitHub Desktop.
Save statwonk/74a09b0abc0248065e850ffe24d7dafa to your computer and use it in GitHub Desktop.
Measuring retweets, for fun!
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