Skip to content

Conversation

@simonpcouch
Copy link
Collaborator

Closes #374. :-)

library(tidyverse)
library(infer)
data(gss)

# partyid coded as factor

gss_rd <- gss %>%  filter(partyid %in% c("rep", "dem"))

class(gss_rd$partyid)
#> [1] "factor"

gss_null<-gss_rd %>% specify(college ~ partyid, success = "degree") %>%
  hypothesize(null = "independence") %>% 
  generate(reps = 1000, type = "permute") %>% 
  calculate(stat = "diff in props", order = c("rep", "dem")) 

gss_stat <- gss_rd %>% specify(college ~ partyid, success = "degree") %>%
  calculate(stat = "diff in props", order = c("rep", "dem")) 

gss_null %>% visualise()+shade_p_value(obs_stat = gss_stat, direction = "both")

# ...or as character
gss_rd <- gss %>%  filter(partyid %in% c("rep", "dem")) %>% mutate(partyid = as.character(partyid) )

class(gss_rd$partyid)
#> [1] "character"

gss_null<-gss_rd %>% specify(college ~ partyid, success = "degree") %>%
  hypothesize(null = "independence") %>% 
  generate(reps = 1000, type = "permute") %>% 
  calculate(stat = "diff in props", order = c("rep", "dem")) 

gss_stat <- gss_rd %>% specify(college ~ partyid, success = "degree") %>%
  calculate(stat = "diff in props", order = c("rep", "dem")) 

gss_null %>% visualise()+shade_p_value(obs_stat = gss_stat, direction = "both")

Created on 2021-04-03 by the reprex package (v1.0.0.9001)

@simonpcouch
Copy link
Collaborator Author

simonpcouch commented Apr 3, 2021

Could be worth a message here, as I can imagine some cases (under resampling with some levels with small n?) where this could be worth noting. x here, though, draws from the data frame inputted to specify (i.e. this happens before resampling with generate), so I don't think we need to warn or add an argument.

@echasnovski
Copy link
Collaborator

Thank you, this looks good!

@github-actions
Copy link

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 26, 2021
@simonpcouch simonpcouch deleted the diff-props-theory-type branch May 19, 2021 15:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent warning in two-sided hypothesis test for difference in proportions on factor vs character variables

3 participants