New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The order of `p` matters for `type = "simulate"` #122

Closed
ismayc opened this Issue Mar 23, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@ismayc
Copy link
Collaborator

ismayc commented Mar 23, 2018

library(infer)
suppressPackageStartupMessages(library(dplyr))
mtcars <- as.data.frame(mtcars) %>%
  mutate(cyl = factor(cyl),
         vs = factor(vs),
         am = factor(am),
         gear = factor(gear),
         carb = factor(carb))
# For reproducibility         
set.seed(2018)   

# Not correct
mtcars %>%
  specify(cyl ~ NULL) %>% # alt: response = cyl
  hypothesize(null = "point", p = c("6" = .25, "4" = .5, "8" = .25)) %>%
  generate(reps = 100, type = "simulate") %>%
  calculate(stat = "Chisq") %>% 
  visualize()

# Correct
mtcars %>%
  specify(cyl ~ NULL) %>% # alt: response = cyl
  hypothesize(null = "point", p = c("4" = .5, "6" = .25, "8" = .25)) %>%
  generate(reps = 100, type = "simulate") %>%
  calculate(stat = "Chisq") %>% 
  visualize()

Created on 2018-03-23 by the reprex package (v0.2.0).

@ismayc ismayc added the bug label Mar 23, 2018

@rpruim

This comment has been minimized.

Copy link

rpruim commented Mar 23, 2018

Side note: If the code above is returning the plot, then you can keep right on going with %>% to modify the plot if you use ggformula. That would allow people to add additional layers, changes themes, reset limits, use different scales, etc., etc. all in your piped flow.

@andrewpbray

This comment has been minimized.

Copy link
Collaborator

andrewpbray commented Mar 27, 2018

Good catch Chester. I thought I coded the order parsing correctly but apparently not!

@rpruim thanks for pointing that out. I didn't know that ggformula enabled that, but it's good to know as we think through how best to have users interact with the visuals.

@rpruim

This comment has been minimized.

Copy link

rpruim commented Mar 27, 2018

You can find examples in the main vignette of the package (which is in another round of edits heading toward an update on CRAN soon-ish). Here is just one example (from the vignette) of how things look in ggformula:

gf_histogram( ~ age, data = Runners, alpha = 0.5, fill = "white",
              binwidth = 5) %>%
  gf_freqpoly( ~ age, color = "skyblue", binwidth = 5, size = 1.5) %>%
  gf_labs(x = "age (years)", title = "Age of runners") %>%
  gf_lims(x = c(20, 80)) %>%
  gf_theme(theme = theme_dark())

image

Should you find something you would like to do that ggformula doesn't support, let us know.

ismayc added a commit that referenced this issue Aug 6, 2018

Merge pull request #176 from echasnovski/calculate-p-order-122
Fix `calculate()` to not depend on order of `p` (fixes #122).

@ismayc ismayc closed this Aug 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment