Skip to content
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

Stratification by 2 variables doesn't respect factor order #101

Open
timwaterhouse opened this issue Dec 11, 2024 · 0 comments
Open

Stratification by 2 variables doesn't respect factor order #101

timwaterhouse opened this issue Dec 11, 2024 · 0 comments

Comments

@timwaterhouse
Copy link

Hi Ron, thanks for the great package that I've gotten a lot of use out of. It seems that when stratifying by 2 factors, those are coerced to characters at some point because the ordering is lost (i.e., ordered alphabetically instead).

In this example, I'd expect xfac to be ordered "b, a, c" and yfac to be ordered "e, d, f". This seems to work when stratifying by only xfac, but not by both.

library(tidyverse)
library(vpc)
obs0 <- simple_data$obs
ids <- obs0 %>%
  distinct(ID) %>% 
  mutate(
    xfac = sample(letters[1:3], n(), replace = TRUE),
    xfac = factor(xfac, levels = c("b", "a", "c")),
    yfac = sample(letters[4:6], n(), replace = TRUE),
    yfac = factor(yfac, levels = c("e", "d", "f"))
  )
sim <- simple_data$sim %>% left_join(ids)
#> Joining with `by = join_by(ID)`
obs <- obs0 %>% left_join(ids)
#> Joining with `by = join_by(ID)`
vpc(sim = sim, obs = obs, stratify = "xfac") + theme_bw()

vpc(sim = sim, obs = obs, stratify = c("xfac", "yfac")) + theme_bw()

Created on 2024-12-11 with reprex v2.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant