Skip to content

Instantly share code, notes, and snippets.

@statwonk

statwonk/retweets.R

Created Dec 30, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.