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

Do we need a way to easily convert pre-calculated statistics into an ARD format? #379

Open
ddsjoberg opened this issue Jan 22, 2025 · 2 comments

Comments

@ddsjoberg
Copy link
Collaborator

Sometimes it will jsut be easier to calculate the quantity you need rather than wrapping it up in a function and processing it through existing ard_*() functions. In the example below, we're taking a pre-calculated dispersion statistic from a negative binomial regression model and adding it to an ARD.

Would this be helpful?

Something like this?

devtools::load_all("/Users/sjobergd/Documents/GitHub/cards")
#> ℹ Loading cards

ard_literal <- function(stats, variable, context = "literal") {
  # check inputs ---------------------------------------------------------------
  set_cli_abort_call()
  check_named_list_and_vector_elements(stats)
  check_string(variable)
  check_string(context)
  
  # build data frame for calculaton --------------------------------------------
  dplyr::tibble("{variable}" := TRUE) |> 
    ard_continuous(
      variables = all_of(variable),
      statistic = everything() ~ list(identity = \(x) stats)
    ) |> 
    dplyr::mutate(
      context = .env$context
    )
}

ard_literal(list(dispersion = 1.1), variable = "age", context = "negative binomial regression")
#> {cards} data frame: 1 x 8
#>   variable   context  stat_name stat_label stat fmt_fn
#> 1      age negative… dispersion  dispersi…  1.1      1
#> ℹ 2 more variables: warning, error

Created on 2025-01-22 with reprex v2.1.1

@Melkiades
Copy link
Contributor

I think this can be useful for tests. I do not know if users will be adopting it though, also because it applies only to one variable (no groups right?)

@ddsjoberg
Copy link
Collaborator Author

I think this can be useful for tests. I do not know if users will be adopting it though, also because it applies only to one variable (no groups right?)

We could add groups to the inputs, but if the results are pre-calculated I imagined grouping wouldn't be necessary...I can't think of a use case

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

2 participants