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 CATEGORICAL DATA IN R
INFERENCE FOR CATEGORICAL DATA IN R
INFERENCE FOR CATEGORICAL DATA IN R
INFERENCE FOR CATEGORICAL DATA IN R
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
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
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
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
Let ' s practice ! IN FE R E N C E FOR C ATE G OR IC AL DATA IN R
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
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
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
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
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
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
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
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
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
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
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
Let ' s practice ! IN FE R E N C E FOR C ATE G OR IC AL DATA IN R
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
INFERENCE FOR CATEGORICAL DATA IN R
INFERENCE FOR CATEGORICAL DATA IN R
INFERENCE FOR CATEGORICAL DATA IN R
INFERENCE FOR CATEGORICAL DATA IN R
INFERENCE FOR CATEGORICAL DATA IN R
INFERENCE FOR CATEGORICAL DATA IN R
INFERENCE FOR CATEGORICAL DATA IN R
INFERENCE FOR CATEGORICAL DATA IN R
INFERENCE FOR CATEGORICAL DATA IN R
INFERENCE FOR CATEGORICAL DATA IN R
INFERENCE FOR CATEGORICAL DATA IN R
INFERENCE FOR CATEGORICAL DATA IN R
INFERENCE FOR CATEGORICAL DATA IN R
INFERENCE FOR CATEGORICAL DATA IN R
INFERENCE FOR CATEGORICAL DATA IN R
INFERENCE FOR CATEGORICAL DATA IN R
INFERENCE FOR CATEGORICAL DATA IN R
INFERENCE FOR CATEGORICAL DATA IN R
Let ' s practice ! IN FE R E N C E FOR C ATE G OR IC AL DATA IN R
Recommend
More recommend