Skip to content

Instantly share code, notes, and snippets.

@juliasilge
Last active December 29, 2019 23:44
Show Gist options
  • Save juliasilge/2af1fd8bf74a84e2d18dde61ffe82cd2 to your computer and use it in GitHub Desktop.
Save juliasilge/2af1fd8bf74a84e2d18dde61ffe82cd2 to your computer and use it in GitHub Desktop.
Log odds with nesting for Tyler
library(tidyverse)
library(tidylo)
library(babynames)
top_names <- babynames %>%
filter(year >= 1950,
year < 1990) %>%
mutate(decade = (year %/% 10) * 10,
decade = paste0(decade, "s")) %>%
group_by(decade) %>%
count(sex, name, wt = n, sort = TRUE) %>% ## sex is your analog to user id
ungroup
name_log_odds <- top_names %>% ## top_names is like your df
nest(data = c(decade, name, n)) %>% ## decade is your analog to month_yr, name is your analog to unigram
mutate(data = map(data, bind_log_odds, decade, name, n)) %>%
unnest(data)
name_log_odds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment