Is Outcome
also a boolean variable? If so, a simple prop.test
will do.
Here's a toy dataset where a judge from the same country is less likely to give a guilty verdict.
library(tidyverse)
n<-1000
dataset<-tibble(country_judge = sample(c(TRUE,FALSE), n,
replace=T, prob=c(0.2,0.8))) %>%
mutate(outcome = ifelse(country_judge,
sample(c("Guilty", "Innocent"), n,
replace=T, prob=c(0.4,0.6)),
sample(c("Guilty", "Innocent"), n,
replace=T, prob=c(0.5,0.5))))
dataset %>%
group_by(country_judge) %>%
summarise(p_guilty=mean(outcome=="Guilty"))
This will give something like:
# A tibble: 2 x 2
country_judge p_guilty
<lgl> <dbl>
1 FALSE 0.5108835
2 TRUE 0.3698630
Now, pull out vectors of trials, and "successes", and feed those into prop.test
.
trials <- dataset %>%
group_by(country_judge) %>%
count() %>%
pull(n)
successes <- dataset %>%
filter(outcome=="Guilty") %>%
group_by(country_judge) %>%
count() %>%
pull(n)
prop.test(successes, trials)
Which gives something like:
2-sample test for equality of proportions with continuity correction
data: successes out of trials
X-squared = 13.068, df = 1, p-value = 0.0003003
alternative hypothesis: two.sided
95 percent confidence interval:
0.06517776 0.21686317
sample estimates:
prop 1 prop 2
0.5108835 0.3698630