h y pothesis test for a proportion
play

H y pothesis test for a proportion IN FE R E N C E FOR C ATE G OR - PowerPoint PPT Presentation

H y pothesis test for a proportion IN FE R E N C E FOR C ATE G OR IC AL DATA IN R Andre w Bra y Assistant Professor of Statistics at Reed College INFERENCE FOR CATEGORICAL DATA IN R INFERENCE FOR CATEGORICAL DATA IN R INFERENCE FOR


  1. H y pothesis test for a proportion IN FE R E N C E FOR C ATE G OR IC AL DATA IN R Andre w Bra y Assistant Professor of Statistics at Reed College

  2. INFERENCE FOR CATEGORICAL DATA IN R

  3. INFERENCE FOR CATEGORICAL DATA IN R

  4. INFERENCE FOR CATEGORICAL DATA IN R

  5. INFERENCE FOR CATEGORICAL DATA IN R

  6. INFERENCE FOR CATEGORICAL DATA IN R

  7. INFERENCE FOR CATEGORICAL DATA IN R

  8. Do half of Americans fa v or capital p u nishment ? gss2016 %>% ggplot(aes(x = cappun)) + geom_bar() p_hat <- gss2016 %>% summarize(mean(cappun == "FAVOR")) %>% pull() p_hat 0.5666667 INFERENCE FOR CATEGORICAL DATA IN R

  9. Do half of Americans fa v or capital p u nishment ? A tibble: 500 x 2 null <- gss2016 %>% replicate stat specify( <fct> <dbl> response = cappun, 1 1 0.48 success = "FAVOR" 2 2 0.447 ) %>% 3 3 0.48 4 4 0.44 hypothesize( 5 5 0.407 null = "point", 6 6 0.52 p = 0.5 7 7 0.413 ) %>% 8 8 0.553 9 9 0.52 10 10 0.467 generate( # … with 490 more rows reps = 500, type = "simulate" ) %>% calculate(stat = "prop") INFERENCE FOR CATEGORICAL DATA IN R

  10. Do half of Americans fa v or capital p u nishment ? ggplot(null, aes(x = stat)) + geom_density() + geom_vline( xintercept = p_hat, color = "red" ) null %>% summarize(mean(stat > p_hat)) %>% pull() * 2 INFERENCE FOR CATEGORICAL DATA IN R

  11. H y pothesis test N u ll h y pothesis : theor y abo u t the state of the w orld . N u ll distrib u tion : distrib u tion of test statistics ass u ming n u ll is tr u e . p -v al u e : a meas u re of consistenc y bet w een n u ll h y pothesis and y o u r obser v ations . high p -v al u e : consistent ( p -v al > alpha ) lo w p -v al u e : inconsistent ( p -v al < alpha ) INFERENCE FOR CATEGORICAL DATA IN R

  12. Let ' s practice ! IN FE R E N C E FOR C ATE G OR IC AL DATA IN R

  13. Inter v als for differences IN FE R E N C E FOR C ATE G OR IC AL DATA IN R Andre w Bra y Assistant Professor of Statistics at Reed College

  14. A q u estion in t w o v ariables Do w omen and men belie v e at di � erent rates ? Let p be the proportion that belie v e in life a � er death . H : p − p = 0 0 female male : p − p ≠ 0 H A female male INFERENCE FOR CATEGORICAL DATA IN R

  15. Do w omen and men ha v e different opinions on life after death ? ggplot(gss2016, aes(x = sex, fill = postlife)) + geom_bar() INFERENCE FOR CATEGORICAL DATA IN R

  16. Do w omen and men ha v e different opinions on life after death ? ggplot(gss2016, aes(x = sex, fill = postlife)) + geom_bar(position = "fill") INFERENCE FOR CATEGORICAL DATA IN R

  17. Do w omen and men ha v e different opinions on life after death ? p_hats <- gss2016 %>% group_by(sex) %>% summarize(mean(postlife == "YES", na.rm = TRUE)) %>% pull() d_hat <- diff(p_hats) d_hat 0.1472851 INFERENCE FOR CATEGORICAL DATA IN R

  18. Generating data from H 0 H : p − p = 0 0 female male There is no association bet w een belief in the a � erlife and the se x of a s u bject . The v ariable postlife is independent from the v ariable sex . ⇒ Generate data b y perm u tation INFERENCE FOR CATEGORICAL DATA IN R

  19. Do w omen and men ha v e different opinions on life after death ? gss2016 %>% specify( response = postlife, explanatory = sex, success = "YES" ) %>% hypothesize(null = "independence") %>% generate(reps = 1, type = "permute") INFERENCE FOR CATEGORICAL DATA IN R

  20. Do w omen and men ha v e different opinions on life after death ? Response: postlife (factor) gss2016 %>% Explanatory: sex (factor) specify( Null Hypothesis: independence postlife ~ sex, # this line is new # A tibble: 137 x 3 success = "YES" # Groups: replicate [1] ) %>% postlife sex replicate hypothesize(null = "independence") %>% <fct> <fct> <int> generate(reps = 1, type = "permute") 1 YES FEMALE 1 2 YES MALE 1 3 YES FEMALE 1 4 YES MALE 1 5 YES MALE 1 6 YES FEMALE 1 7 NO FEMALE 1 INFERENCE FOR CATEGORICAL DATA IN R

  21. Do w omen and men ha v e different opinions on life after death ? Response: postlife (factor) gss2016 %>% Explanatory: sex (factor) specify( Null Hypothesis: independence postlife ~ sex, # A tibble: 137 x 3 success = "YES" # Groups: replicate [1] ) %>% postlife sex replicate hypothesize(null = "independence") %>% <fct> <fct> <int> generate(reps = 1, type = "permute") 1 YES FEMALE 1 2 NO MALE 1 3 NO FEMALE 1 4 YES MALE 1 5 YES MALE 1 6 YES FEMALE 1 7 YES FEMALE 1 INFERENCE FOR CATEGORICAL DATA IN R

  22. Do w omen and men ha v e different opinions on life after death ? gss2016 %>% specify(postlife ~ sex, success = "YES") %>% hypothesize(null = "independence") %>% generate(reps = 500, type = "permute") %>% calculate(stat = "diff in props", order = c("FEMALE", "MALE")) Warning message: Removed 13 rows containing missing values. INFERENCE FOR CATEGORICAL DATA IN R

  23. Do w omen and men ha v e different opinions on life after death ? ggplot(null, aes(x = stat)) + geom_density() + geom_vline(xintercept = d_hat, color = "red") These data s u ggest that there is a di � erence bet w een se x es in the belief of life a � er death . INFERENCE FOR CATEGORICAL DATA IN R

  24. Let ' s practice ! IN FE R E N C E FOR C ATE G OR IC AL DATA IN R

  25. Statistical errors IN FE R E N C E FOR C ATE G OR IC AL DATA IN R Andre w Bra y Assistant Professor of Statistics at Reed College

  26. INFERENCE FOR CATEGORICAL DATA IN R

  27. INFERENCE FOR CATEGORICAL DATA IN R

  28. INFERENCE FOR CATEGORICAL DATA IN R

  29. INFERENCE FOR CATEGORICAL DATA IN R

  30. INFERENCE FOR CATEGORICAL DATA IN R

  31. INFERENCE FOR CATEGORICAL DATA IN R

  32. INFERENCE FOR CATEGORICAL DATA IN R

  33. INFERENCE FOR CATEGORICAL DATA IN R

  34. INFERENCE FOR CATEGORICAL DATA IN R

  35. INFERENCE FOR CATEGORICAL DATA IN R

  36. INFERENCE FOR CATEGORICAL DATA IN R

  37. INFERENCE FOR CATEGORICAL DATA IN R

  38. INFERENCE FOR CATEGORICAL DATA IN R

  39. INFERENCE FOR CATEGORICAL DATA IN R

  40. INFERENCE FOR CATEGORICAL DATA IN R

  41. INFERENCE FOR CATEGORICAL DATA IN R

  42. INFERENCE FOR CATEGORICAL DATA IN R

  43. INFERENCE FOR CATEGORICAL DATA IN R

  44. Let ' s practice ! IN FE R E N C E FOR C ATE G OR IC AL DATA IN R

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend