-
Notifications
You must be signed in to change notification settings - Fork 28
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
draw
forgets order of ordered factor
#284
Comments
Yeah; this is a known infelicity of the current way I return everything as a single tibble; we can't merge factors (ordered or otherwise) with different levels and wouldn't want to anyway. I think I really want to return a nested tibble with 1 row per effect (1 row for each smooth or parametric effect), which will allow for storage of the levels as we won't need to convert them to character to bind all the effects together. But that would be quite a change to the UI and would fail as soon as someone unnested the tibble... Right now, the best I can think of is to attach another attribute the carries the factor levels in a list, and make sure I preserve that attribute through any subsetting operations. |
… missed adding a period to the names of objects returned by parametric_effects
…c_effects objects that got missed in 0.9.0; bump patch version
I am sorry to reopen this issue @gavinsimpson , but I think there is still a problem: the solution breaks down if there are more than one factor explanatory variables and the variable in question is not the first in Continuing the original example:
Now, |
Thanks; I'll take a look |
Hmm, I can't reproduce this @tamas-ferenci, at least not with the latest CRAN release. > m |> parametric_effects(select = c("var", "month"))
# A tibble: 12 × 5
.term .type .level .partial .se
<chr> <chr> <chr> <dbl> <dbl>
1 month ordered Jan -0.0444 0.352
2 month ordered Feb 0.337 0.351
3 month ordered Mar 0.266 0.331
4 month ordered Apr -0.0198 0.298
5 month ordered May -0.297 0.263
6 month ordered Jun -0.215 0.266
7 month ordered Jul -0.0351 0.297
8 month ordered Aug -0.191 0.336
9 month ordered Sep -0.144 0.348
10 month ordered Oct 0.344 0.354
11 var factor a 0 0
12 var factor b 0.0294 0.294 |
That's crazy! I think I know what happened: you used |
@tamas-ferenci Yes, they are essentially identical, although I see at least two problems and I can now reproduce your findings:
(My example works, because I sued I'll fix both of these issues this week. |
The problem is happening in this code effects <- map_df(valid_terms,
.f = fun, data = data, pred = pred,
vars = vars
)
if (unnest) {
f_levels <- attr(effects, "factor_levels")
effects <- unnest(effects, cols = "data") |>
relocate(c(".partial", ".se"), .after = last_col())
attr(effects, "factor_levels") <- f_levels
} from Only one set of levels is preserved in the If so, perhaps best to not coerce to a data frame at the stage that |
Aaaah, I see! (I automatically assumed that the second argument is called |
@tamas-ferenci Sorry if I was unclear; your code is correct, mine example wasn't. The argument is called The bug is real; I'm testing a fix at the moment and should have it on GitHub in a couple of hours. |
OK, I understand! Great, thank you! |
This seems to be fixed again; thanks for the report @tamas-ferenci |
I checked it @gavinsimpson , and it seems to be working perfectly, thank you very much! |
Thanks @tamas-ferenci |
Everything evaluates fine, but the terms are not ordered after
parametric_effects
and plotted in alphabetical order.The factor and its ordering look to become purposefully uncoupled into row order, an "ordered" type, and an unordered character representation of the levels in
parametric_effects
. The row ordering is not passed on to the base plotting step ofdraw_parametric_effect
.The text was updated successfully, but these errors were encountered: