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

Return more summary stats for the ard_stack(by) variable #219

Closed
ddsjoberg opened this issue Apr 2, 2024 · 2 comments · Fixed by #220
Closed

Return more summary stats for the ard_stack(by) variable #219

ddsjoberg opened this issue Apr 2, 2024 · 2 comments · Fixed by #220

Comments

@ddsjoberg
Copy link
Collaborator

ddsjoberg commented Apr 2, 2024

library(cards)
packageVersion("cards")
#> [1] '0.1.0.9008'

# the little n and p are missing for the overall tabulation of ARM
ard_stack(
  ADSL, 
  by = ARM, 
  .overall = TRUE,
  ard_categorical(variables = AGEGR1)
) |> 
  dplyr::filter(variable %in% "ARM")
#> {cards} data frame: 3 x 11
#>   group1 group1_level variable variable_level stat_name stat_label stat
#> 1   <NA>                   ARM        Placebo         N          N  254
#> 2   <NA>                   ARM      Xanomeli…         N          N  254
#> 3   <NA>                   ARM      Xanomeli…         N          N  254
#> ℹ 4 more variables: context, fmt_fn, warning, error

# we still get overall results when `.overall = FALSE`
ard_stack(
  ADSL, 
  by = ARM, 
  .overall = FALSE,
  ard_categorical(variables = AGEGR1)
) |> 
  dplyr::filter(variable %in% "ARM")
#> {cards} data frame: 3 x 11
#>   group1 group1_level variable variable_level stat_name stat_label stat
#> 1   <NA>                   ARM        Placebo         N          N  254
#> 2   <NA>                   ARM      Xanomeli…         N          N  254
#> 3   <NA>                   ARM      Xanomeli…         N          N  254
#> ℹ 4 more variables: context, fmt_fn, warning, error

Created on 2024-04-02 with reprex v2.1.0

@ddsjoberg ddsjoberg changed the title Issue with ard_categorical(.overall) Issue with ard_stack(.overall) Apr 2, 2024
@ddsjoberg
Copy link
Collaborator Author

FYI @statasaurus

@ddsjoberg
Copy link
Collaborator Author

ddsjoberg commented Apr 2, 2024

Ahh, I mis-read the docs. Nothing wrong at all with the .overall argument. When there is a by argument AND .overall = TRUE, then we get the results re-calculated with by=NULL (essentially, we can add a new column call Overall to our table with all treatment groups combined. This is exactly what is happening, and what we want

I think the misunderstanding is regarding this chunk that executes when there is a by variable present. We want not just the total N, but the other summary stats for the by group as well. In the case of a univariate tabulation, N is the same for every level of the by variable.

ard_categorical(
        data = data,
        variables = all_of(by),
        statistic = everything() ~ categorical_summary_fns("N")
      )

ddsjoberg added a commit that referenced this issue Apr 2, 2024
@ddsjoberg ddsjoberg changed the title Issue with ard_stack(.overall) Return more summary stats for the ard_stack(by) variable Apr 2, 2024
ddsjoberg added a commit that referenced this issue Apr 3, 2024
**What changes are proposed in this pull request?**
* Updated `ard_stack()` to return `n`, `p`, and `N` for the `by`
variable when specified. Previously, it only returned `N` which is the
same for all levels of the by variable. (#219)

**Reference GitHub issue associated with pull request.** _e.g., 'closes
#<issue number>'_
closes #219


--------------------------------------------------------------------------------

Pre-review Checklist (if item does not apply, mark is as complete)
- [ ] **All** GitHub Action workflows pass with a ✅
- [ ] PR branch has pulled the most recent updates from master branch:
`usethis::pr_merge_main()`
- [ ] If a bug was fixed, a unit test was added.
- [ ] Code coverage is suitable for any new functions/features
(generally, 100% coverage for new code): `devtools::test_coverage()`
- [ ] Request a reviewer

Reviewer Checklist (if item does not apply, mark is as complete)

- [ ] If a bug was fixed, a unit test was added.
- [ ] Run `pkgdown::build_site()`. Check the R console for errors, and
review the rendered website.
- [ ] Code coverage is suitable for any new functions/features:
`devtools::test_coverage()`

When the branch is ready to be merged:
- [ ] Update `NEWS.md` with the changes from this pull request under the
heading "`# cards (development version)`". If there is an issue
associated with the pull request, reference it in parentheses at the end
update (see `NEWS.md` for examples).
- [ ] **All** GitHub Action workflows pass with a ✅
- [ ] Approve Pull Request
- [ ] Merge the PR. Please use "Squash and merge" or "Rebase and merge".
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

Successfully merging a pull request may close this issue.

1 participant