Last active
October 5, 2018 20:55
-
-
Save Dpananos/ff9ef2edcff42884aee939da9695d7ab 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
library(tidyverse) | |
N = 1000 | |
#So imagine we have all the data we need for people with low birth weights | |
race = sample(c('Caucasian','AfricanAmerican'), size = N, replace = T) #Race of people who have low birth weight | |
birthweight = sample(c('Low','Normal'), size = N, replace = T) | |
social_class = sample(c('Upper','Middle','Lower'), size = N, replace = T) #Social class of people with low birth weight. These are the strata | |
mydata = data_frame(race = race, social_class = social_class, birthweight = birthweight) #Imagine these are all the people with low birth weights | |
normal.bw = mydata %>% | |
group_by(race,social_class,birthweight) %>% | |
summarise(N = n()) %>% | |
ungroup %>% | |
filter(birthweight == 'Normal') %>% | |
spread(race,N) %>% | |
mutate(Ratio_low.nw = AfricanAmerican/Caucasian) %>% | |
select(social_class, Ratio_low.nw) | |
low.bw = mydata %>% | |
group_by(race,social_class,birthweight) %>% | |
summarise(N = n()) %>% | |
ungroup %>% | |
filter(birthweight == 'Low') %>% | |
spread(race,N) %>% | |
mutate(Ratio_low.bw = AfricanAmerican/Caucasian) %>% | |
select(social_class,Ratio_low.bw) | |
normal.bw %>% | |
left_join(low.bw) %>% | |
mutate(Ratio.of.Ratio = Ratio_low.bw/Ratio_low.nw) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment