Function for safe use of hypothesis argument #1429
Replies: 2 comments 5 replies
-
Thanks for posting. This sounds very interesting! I do use a function internally to do something like that, but I've found the problem to be very difficult. The issue is that unique row identifiers depend on columns that vary depending on the function and on user input. There is something like this here: marginaleffects/R/get_labels.R Line 1 in 21ab438 But it's not perfect and does not guarantee uniques. Frankly, I wasn't convinced this could be done in a general predictable way, so I gave up on this idea. But I'd be curious to know what you are using. |
Beta Was this translation helpful? Give feedback.
-
Done. This is my final version for now; I think it actually ends up handling fairly well. The clunky aspect of needing the output of the marginaleffects function without the hypothesis argument is unavoidable, as is the necessity of using exactly the same variables (or newdata) argument for the subsequent call with the hypothesis argument. For the latter, it might make sense for users to explicitly save their variables/newdata argument as its own object before calling the function for the first time; this would ensure consistency.
The function retains names in the hypothesis argument, so the output can still be made more easily legible by naming elements of the hypothesis character vector. By the way, thanks for developing this package, it's been very useful to me! |
Beta Was this translation helpful? Give feedback.
-
Hi all,
as documented in the package and in the warning provided when calling avg_predictions using the hypothesis argument below, the b* wildcard may not be a stable parameter when code is rerun.
I do a lot of analyses of multifactorial designs where third- or fourth-order interactions are of interest, often with specific contrasts, so I rely on this function a lot. To keep my analyses reproducible, I recently wrote a function
as_marginaleffects_hypothesis
that takes a user's input based on term values and translates it to row numbers, given a base avg_predictions output to work from. This allows a user to save the output of avg_predictions without the hypothesis argument, then call as_marginaleffects_hypothesis later on to get a b*-style hypothesis argument robustly.Would there be any interest in my sharing this function? I'm not familiar with github (neither etiquette nor typical procedures), so apologies if this is impertinent or asked in the wrong place. If there is interest, I can share my code here or elsewhere!
Best,
A. Krishna
Beta Was this translation helpful? Give feedback.
All reactions