Guest User

Untitled

a guest
Mar 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. library(tidyverse)
  2. n<-1000
  3. dataset<-tibble(country_judge = sample(c(TRUE,FALSE), n,
  4. replace=T, prob=c(0.2,0.8))) %>%
  5. mutate(outcome = ifelse(country_judge,
  6. sample(c("Guilty", "Innocent"), n,
  7. replace=T, prob=c(0.4,0.6)),
  8. sample(c("Guilty", "Innocent"), n,
  9. replace=T, prob=c(0.5,0.5))))
  10.  
  11. dataset %>%
  12. group_by(country_judge) %>%
  13. summarise(p_guilty=mean(outcome=="Guilty"))
  14.  
  15. # A tibble: 2 x 2
  16. country_judge p_guilty
  17. <lgl> <dbl>
  18. 1 FALSE 0.5108835
  19. 2 TRUE 0.3698630
  20.  
  21. trials <- dataset %>%
  22. group_by(country_judge) %>%
  23. count() %>%
  24. pull(n)
  25.  
  26. successes <- dataset %>%
  27. filter(outcome=="Guilty") %>%
  28. group_by(country_judge) %>%
  29. count() %>%
  30. pull(n)
  31.  
  32. prop.test(successes, trials)
  33.  
  34. 2-sample test for equality of proportions with continuity correction
  35.  
  36. data: successes out of trials
  37. X-squared = 13.068, df = 1, p-value = 0.0003003
  38. alternative hypothesis: two.sided
  39. 95 percent confidence interval:
  40. 0.06517776 0.21686317
  41. sample estimates:
  42. prop 1 prop 2
  43. 0.5108835 0.3698630
Add Comment
Please, Sign In to add comment