Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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"))
- # A tibble: 2 x 2
- country_judge p_guilty
- <lgl> <dbl>
- 1 FALSE 0.5108835
- 2 TRUE 0.3698630
- 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)
- 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
Add Comment
Please, Sign In to add comment