# Odds Ratios for tables bigger than 2x2

Hi, I need to understand odds ratio for more than 2x2 table, eg. for 2x3 table. How do we calculate it ? Obviously it can be calculated only for 2x2 so we must choose levels of categorical variable or combine/collapse those levels in order to get 2x2 table. Does anybody has got any good examples how it should be done, please ?
Here is my data:

``````dat1 <- structure(list(
Parent = c(
"Both", "Both", "One", "One", "Neither",
"Neither"
), Child = c("Yes", "No", "Yes", "No", "Yes", "No"),
Counts = c("401", "1381", "417", "1824", "189", "1169")
), row.names = 2:7, class = "data.frame")
``````

So here we have got a scenario when both parents smoke, one or neither of them are smokers, and I want to calculate odds ratios about their children's decision to start smoking depending on the fact, that parent(s) smokes or not. Please help.

I have got a question:

how to transform this dataframe: into this: Hello,

You can use a combination of `case_when` and `group_by` to accomplish this.
Define the grouped variable beforehand and then summarize on it:

``````dat1 <- structure(list(
Parent = c(
"Both", "Both", "One", "One", "Neither",
"Neither"
), Child = c("Yes", "No", "Yes", "No", "Yes", "No"),
Counts = c("401", "1381", "417", "1824", "189", "1169")
), row.names = 2:7, class = "data.frame")

library(dplyr)

table1 <-
dat1 %>%
mutate(
Counts = as.numeric(Counts),
combined_group = case_when(
Parent == 'Both' ~ 'Both',
TRUE ~'Max_1' #name of combined group
)
) %>%
group_by (combined_group) %>%
summarise(Yes = sum(Counts[Child == 'Yes']),
No = sum(Counts[Child == 'No'])
)
``````

Gives the following table: Thank you that was very helpful.