Add quantiles parameter to graph.curve.params()#434
Conversation
Codecov ReportAttention: Patch coverage is ✅ All tests successful. No failed tests found.
|
|
📕 Preview documentation for this PR has been cleaned up. |
|
I am not sure why the “Check NEWS.md Changelog” keeps failing, even though I have added the update to the NEWS.md file. This PR adds an input argument to control which quantile curves are displayed. However, I realized it would also be helpful to include an additional argument to control the color of the chains. Currently, each chain is plotted with a different color, but I would like to make this behavior optional — so users can choose between showing different colors for each chain or using the same color (e.g., black) for all chains regardless of how many there are. |
@Kwan-Jenny It was an out of date Github Actions workflow, sorry; fixed now! See UCD-SERG/serodynamics#95 for details |
@Kwan-Jenny I agree! Let's start a separate PR for this feature; I created Issue #436 to track it. |
| show_quantiles = TRUE, | ||
| show_all_curves = FALSE, | ||
| alpha_samples = 0.3 | ||
| alpha_samples = 0.3, | ||
| quantiles = NULL |
There was a problem hiding this comment.
I'm not sure whether we need both the show_quantiles and quantiles arguments; I think we might want to just have quantiles, with default value c("p10", "med", "p90"), and if the user sets quantiles = NULL, that means don't show the quantiles.
@kaiemjoy @kristinawlai @sschildhauer thoughts?
There was a problem hiding this comment.
also, maybe we should have the quantiles argument be numeric instead of character strings?
There was a problem hiding this comment.
also, maybe we should have the quantiles argument be numeric instead of character strings?
... and then the user could specify any arbitrary set of quantiles, not just ones we hard-coded
There was a problem hiding this comment.
@d-morrison I completely agree. I added an extra input argument to avoid altering the original code, as I didn’t want to risk breaking anything. But I see now that your approach is more user-friendly and will likely make things easier for others.
There was a problem hiding this comment.
@Kwan-Jenny that's a good concern!
In this particular case, the show_quantiles argument is a relatively recent addition, added after the last CRAN release, so I think we can just replace it, as long as we explain the change in NEWS.md.
quantiles parameter to graph.curve.params()
sschildhauer
left a comment
There was a problem hiding this comment.
Hi Kwan, after implementing the below suggestions please let me know if you want me to review again and I would be happy to jump back in.
sschildhauer
left a comment
There was a problem hiding this comment.
Not much left! Only one simple documentation change, then I think good to request from Ezra.
Co-authored-by: Samuel Schildhauer <165851188+sschildhauer@users.noreply.github.com>
…calculator into update_graph_curve erro fixed
d-morrison
left a comment
There was a problem hiding this comment.
Looking good, but I have some questions; please see comments.
| min = min(.data$res, 0.9), | ||
| max = max(.data$res, 2000) | ||
| min = min(.data$res, na.rm = TRUE), | ||
| max = max(.data$res, na.rm = TRUE) |
There was a problem hiding this comment.
I’m not entirely sure since this part was coded a few months ago, but I think I changed it to make the function more general and data-driven. Instead of using hardcoded limits, it now reflects the actual range of the model output, and na.rm = TRUE helps handle any potential missing values. It seemed like a safer and more flexible approach for broader use.
| #' show(plot2) | ||
| #' plot2 <- graph.curve.params(curve, show_all_curves = TRUE, | ||
| #' quantiles = c(0.1, 0.5, 0.9)) | ||
| #' print(plot2) |
There was a problem hiding this comment.
please use the external example file approach (as Sam suggested, for any examples ≥3 lines long); that way, the examples will get linted properly.
| ) | ||
| ) | ||
|
|
||
| # FIXED: avoid use of dot in slice() context |
There was a problem hiding this comment.
not sure what this comment means; is it still relevant?
There was a problem hiding this comment.
comments in code files should explain what the code currently does; the comments should not discuss how the code previously looked. Comments like this one should be posted on GitHub in the PR.
There was a problem hiding this comment.
I somehow changed it, possibly due to masking or linting issues at that time — I'm not entirely sure, so I reverted it to the original.
| dT <- # nolint: object_linter | ||
| data.frame(t = tx2) |> | ||
| mutate(ID = dplyr::row_number()) |> | ||
| pivot_wider( | ||
| names_from = "ID", | ||
| values_from = "t", | ||
| names_prefix = "time" | ||
| ) |> | ||
| dplyr::slice( | ||
| rep( | ||
| seq_len(dplyr::n()), | ||
| each = nrow(d) | ||
| ) | ||
| ) | ||
|
|
||
| # FIXED: avoid use of dot in slice() context | ||
| dT_base <- data.frame(t = tx2) |> # nolint: object_name_linter | ||
| dplyr::mutate(ID = dplyr::row_number()) |> | ||
| tidyr::pivot_wider(names_from = "ID", | ||
| values_from = "t", | ||
| names_prefix = "time") | ||
| dT <- dT_base |> # nolint: object_name_linter | ||
| dplyr::slice(rep(seq_len(nrow(dT_base)), each = nrow(d))) |
There was a problem hiding this comment.
I can't tell what changed here or why; please explain in a comment?
There was a problem hiding this comment.
PS - it would help if the formatting changed as little as possible, so that it's easier to tell which parts are the same and which parts are changed.
There was a problem hiding this comment.
I somehow changed it as above, possibly due to masking or linting issues at the time — I'm not entirely sure, so I reverted it back to the original here as well.
| message( | ||
| "Graphing curves for antigen isotypes: ", | ||
| paste(antigen_isos, collapse = ", ") | ||
| ) | ||
| message("Graphing curves for antigen isotypes: ", | ||
| paste(antigen_isos, collapse = ", ")) |
There was a problem hiding this comment.
why did you reformat these lines? was there a lint? If not, please try to avoid changing lines that are unrelated to the goals of your PR.
There was a problem hiding this comment.
I think I accidentally made edits while working with the linter, so I reverted the changes and restored the original formatting.
d-morrison
left a comment
There was a problem hiding this comment.
Please wrap up this PR asap; there are additional extensions we want to make to this function, and if we make those extensions first, it will probably cause merge conflicts for this PR.
| ) | ||
| ) | ||
|
|
||
| # FIXED: avoid use of dot in slice() context |
There was a problem hiding this comment.
comments in code files should explain what the code currently does; the comments should not discuss how the code previously looked. Comments like this one should be posted on GitHub in the PR.
| dT <- # nolint: object_linter | ||
| data.frame(t = tx2) |> | ||
| mutate(ID = dplyr::row_number()) |> | ||
| pivot_wider( | ||
| names_from = "ID", | ||
| values_from = "t", | ||
| names_prefix = "time" | ||
| ) |> | ||
| dplyr::slice( | ||
| rep( | ||
| seq_len(dplyr::n()), | ||
| each = nrow(d) | ||
| ) | ||
| ) | ||
|
|
||
| # FIXED: avoid use of dot in slice() context | ||
| dT_base <- data.frame(t = tx2) |> # nolint: object_name_linter | ||
| dplyr::mutate(ID = dplyr::row_number()) |> | ||
| tidyr::pivot_wider(names_from = "ID", | ||
| values_from = "t", | ||
| names_prefix = "time") | ||
| dT <- dT_base |> # nolint: object_name_linter | ||
| dplyr::slice(rep(seq_len(nrow(dT_base)), each = nrow(d))) |
There was a problem hiding this comment.
PS - it would help if the formatting changed as little as possible, so that it's easier to tell which parts are the same and which parts are changed.
Co-authored-by: Douglas Ezra Morrison <demorrison@ucdavis.edu>
Co-authored-by: Douglas Ezra Morrison <demorrison@ucdavis.edu>
…t I undid it so I can keep original
…'m not entirely sure, so I reverted it to the original.
d-morrison
left a comment
There was a problem hiding this comment.
Thanks! Looks good. I handled the merge conflicts in #454; will merge both shortly!
This patch extends our antibody‐decay plotting helper by introducing a new quantiles argument, which lets the caller specify an arbitrary subset of quantiles to render (e.g. just the 50% band). All existing behavior is preserved when quantiles is unset. In order to exercise the new API we also:
All existing examples and tests have been left intact, and no existing behavior changes when quantiles is not supplied. This new option gives callers full control over which percentile bands to display.