# How to compare two groups + binary variable?

Sorry about my language, i'm from Brazil

I need help about which test should i use to compare differences between two groups that answered a binary varible

In my case, the groups are Sex (male or female) and the binary variable is presence of symptoms (yes or no). I want to know if the difference in the prevalence between the groups is statistical significant.

I used Fisher's Exact Test, is it right?

• Dear Luiz, welcome on CV. No need to by sorry about the language, majority of people here are not native English speakers. Have you read any resources already? Show that you put some effort in finding an answer and explain why you have doubts about the test you used. – hans Nov 19 '19 at 21:56

You can produce a Fisher’s exact test via the fisher.test() function in R. Fisher’s exact test evaluates the null hypothesis of independence of rows and columns in a contingency table with fixed marginals.

set.seed(2401)

sex    <- sample(c("M","F"), 20, replace=T)

tab <- table(age, sex); tab

fisher.test(tab)

#        Fisher's Exact Test for Count Data

#data:  tab
#p-value = 0.01223
#alternative hypothesis: two.sided


The fisher.test() function can be applied to any two-way table with two or more rows and columns, not just a $$2 \times 2$$ table.