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

[Question]: summarize_vars_in_cols no longer exists #931

Closed
3 tasks done
imazubi opened this issue May 24, 2023 · 4 comments · Fixed by #938
Closed
3 tasks done

[Question]: summarize_vars_in_cols no longer exists #931

imazubi opened this issue May 24, 2023 · 4 comments · Fixed by #938
Assignees
Labels
bug Something isn't working enhancement

Comments

@imazubi
Copy link
Contributor

imazubi commented May 24, 2023

What is your question?

Hi Nest folks,

In older versions (< 0.8.0) of tern I was using summarize_vars_in_cols but I just saw in the later versions this function is no longer an exported object (breaking change for me). Is there any alternative so that we can summarize the statistics in columns?

This was the file
Thanks,

IZ

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines.

Security Policy

  • I agree to follow this project's Security Policy.
@imazubi imazubi added the question Further information is requested label May 24, 2023
@Melkiades
Copy link
Contributor

Melkiades commented May 24, 2023

We had to change its name and behavior because it was not paginating correctly. You can find the renaming commit here . It is virtually the same with the difference that it uses analyze instead of summarize which is the correct way to produce analyze rows (previously they were content rows, i.e. label rows with results). Here you can find the main change. Being it on the column space, having "label-content" does not make a lot of sense, and therefore the change from summarize_row_groups into analyze_colvars.

In practice for you, it is enough to change the name of the function into analyze_vars_in_cols and maybe some parameter name (e.g. vars instead of var). Let me know if this works for you

ps: the renaming should be in the news file, I do not know if it was correctly propagated afterward.

@Melkiades Melkiades reopened this May 24, 2023
@imazubi
Copy link
Contributor Author

imazubi commented May 25, 2023

Thanks @Melkiades .

From what I am seeing, this works so far so good.

basic_table() %>%
  split_rows_by("SEX") %>%
  analyze_vars_in_cols(
    vars = c("AGE"),
    .stats = c("n", "mean", "mean_ci", "mean_pval"),
    .labels = c("n" = "n", "mean" = "mean", "mean_ci" = "mean CI", "mean_pval" = "Mean P-value"),
    nested = FALSE
  ) %>%
  build_table(df = ex_adsl) 

However, I was trying to first get overall statistics and then split rows by two variables to get the same statistics. See the below example where I am just splitting by one variable.

basic_table() %>%
  split_rows_by("SEX") %>%
  analyze_vars_in_cols(
    vars = c("AGE"),
    .stats = c("n", "mean", "mean_ci", "mean_pval"),
    .labels = c("n" = "n", "mean" = "mean", "mean_ci" = "mean CI", "mean_pval" = "Mean P-value"),
    nested = FALSE
  ) %>%
  split_rows_by("RACE", nested = FALSE) %>%
  analyze_vars_in_cols(
    vars = c("AGE"),
    .stats = c("n", "mean", "mean_ci", "mean_pval"),
    .labels = c("n" = "n", "mean" = "mean", "mean_ci" = "mean CI", "mean_pval" = "Mean P-value"),
    nested = FALSE
  ) %>%
  build_table(df = ex_adsl) 

I tried with the nested argument but did not work. I was able to do this with the former summarize_vars_in_cols()
image

> packageVersion("rtables")
[1] ‘0.6.0.3’

@Melkiades Melkiades added bug Something isn't working enhancement and removed question Further information is requested labels May 25, 2023
@Melkiades Melkiades self-assigned this May 25, 2023
@Melkiades
Copy link
Contributor

I think what you ask for makes sense to implement again. We do not have currently any need for this mixed behavior but we should support it. I am working on it ;)

Melkiades added a commit that referenced this issue Jun 6, 2023
Fixes #931 and #936

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
@Melkiades
Copy link
Contributor

@imazubi now you can do it with something like the following. Note that the switcher between summarize and analyze is a flat called do_summarize* and you must do the split in cols only once. Also, note that every row split should have the child labels off (hidden). It is possible that we will converge on a more general solution in the future, but this allows now to do what you wanted with the plus that it can be paginated and sorted correctly.

# More nesting
  lyt <- basic_table() %>%
    split_rows_by("SEX") %>%
    analyze_vars_in_cols(
      vars = "AGE",
      do_summarize_row_groups = TRUE
    ) %>%
    split_rows_by("RACE", child_labels = "hidden", split_fun = drop_split_levels) %>%
    analyze_vars_in_cols(
      vars = "AGE",
      split_col_vars = FALSE,
      do_summarize_row_groups = TRUE
    ) %>%
    split_rows_by("ARM", child_labels = "hidden", split_fun = drop_split_levels) %>%
    analyze_vars_in_cols(
      vars = "AGE",
      split_col_vars = FALSE,
      do_summarize_row_groups = TRUE
    ) %>%
    split_rows_by("STRATA1", child_labels = "hidden", split_fun = drop_split_levels) %>%
    analyze_vars_in_cols(
      vars = "AGE",
      split_col_vars = FALSE
    )

  tbl <- testthat::expect_silent(build_table(lyt, df = tern_ex_adpp))

  # Again sorting works
  tbl_sorted <- sort_at_path(tbl, c("SEX", "*", "RACE"), cont_n_onecol(1))
  tbl_sorted <- sort_at_path(tbl_sorted, c("SEX", "*", "RACE", "*", "ARM", "*", "STRATA1"), scorefun(1))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants