0
$\begingroup$

I am working with the nhanes data from 2017-2018. I want to determine the relative risk of being overweight (Adipös) when being "Poor". And this grouped by Gender and Ethnicity. So far I have written this:

DurchgangJ%>%
  mutate( bmi = Gewicht / (Körpergröße/100)^2 ) %>%
  filter( Lebensalter >= 18 )%>%
  filter(!is.na(bmi))%>%
  filter(!is.na(Ratio))%>%
  mutate (Poor = Ratio < 1.3)%>%
  mutate (nichtarme = Ratio >= 1.3)%>%
  mutate (Adipös= bmi>=30)%>%
  mutate (Normal= bmi<30)%>%
  group_by(Geschlecht, Ethnie)%>%
  summarise (Arme = sum(Poor), Nicht_Arm= sum(nichtarme), Adipöse = sum (Adipös), Normal_Gewicht= sum (Normal))

which gives me the number of poor, overweight, normal weight and not poor people per gender and ethnicity: enter image description here

I want to make the following calculations =

R1 = amount of overweight (Adipöse) not poor People (Nicht_Arm) / not poor people

R2 = amount of overweight poor people / poor people (Arme)

and then R2/R1

I got all the values I need apart from the amount of overweight not poor people and the amount of overweight poor people. I was thinking to maybe use the if/else function but I did not manage to make it work.

I am relatively new to R and therefore don't know really how to summarize TRUE and FALSE values. Because all I need for the overweight non poor people is the amount of where in both columns Adipös and Nicht_Arm it says TRUE.

Thank you for your help

$\endgroup$

1 Answer 1

0
$\begingroup$

This is more of a programming than a data science question and is therefore better suited to the stackoverflow stackexchange page. Without having a data sample it is bit difficult, but I would expect something like this to at least get close to what you're looking for:

DurchgangJ %>%
  mutate(bmi = Gewicht / (Körpergröße/100)^2) %>%
  filter(Lebensalter >= 18)%>%
  filter(!is.na(bmi))%>%
  filter(!is.na(Ratio))%>%
  mutate(Poor = Ratio < 1.3)%>%
  mutate(Overweight = bmi > 30)%>%
  group_by(Geschlecht, Ethnie)%>%
  summarise(
      R1 = sum(Overweight & !Poor) / sum(!Poor).
      R2 = sum(Overweight & Poor) / sum(Poor)
    )
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.