-
Notifications
You must be signed in to change notification settings - Fork 24
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
Interval support functions: add/remove impute (#379) #384
base: main
Are you sure you want to change the base?
Interval support functions: add/remove impute (#379) #384
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've not yet reviewed the tests since I requested some bigger changes in the other code.
R/intervals_support_funs.R
Outdated
#' @param data A PKNCAdata object containing the intervals and data components. | ||
#' @param target_impute A character string specifying the imputation method to be removed. | ||
#' @param target_params A character vector specifying the parameters to be targeted (optional). If missing, all TRUE in the intervals are taken. | ||
#' @param target_groups A named list specifying the intervals to be targeted (optional). If missing, all relevant groups are considered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the concept of how you've implemented this. Please make this into a data.frame so that it can work more simply with the way people are accustomed to working with intervals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey data
will also be the intervals dataframe. I guess in this case we cannot guess the impute column always, sobwould need another arg
Indeed I think using a dataframe as an input would make a lot of sense also to match the intervals for the target_groups
arg, which we can call instead something like target_intervals
. Here is then an example:
If this is my initial interval table:
USUBJID | ANALYTE | cmax | tmax | aucinf.pred | impute |
---|---|---|---|---|---|
001 | Analyte1 | TRUE | TRUE | TRUE | start_predose |
I would then like to remove only for cmax and tmax the imputation, while keeping it for the other parameters:
interval_remove_impute(PKNCAdata$intervals,
target_impute = "start_predose",
target_params = c("cmax", "tmax"),
target_intervals = data.frame(ANALYTE="Analyte1") )
This produces:
USUBJID | ANALYTE | cmax | tmax | aucinf.pred | impute |
---|---|---|---|---|---|
001 | Analyte1 | FALSE | FALSE | TRUE | start_predose |
001 | Analyte1 | TRUE | TRUE | FALSE | NA |
That way we keep it intuitive: target_intervals
indicates the rows to be considered (even if it can also contain parameter or impute specifications) while target_params
the columns for which the removal applies.
…ute, improve example
…tes $impute if missing
…s order (with optional arg to specify)
I think all the demanded changes were implemented. The tests should also be complete. I added additional arguments to control the specific behavior of the functions:
Feel free to express any concern, propose a renaming/removal of arguments or re-specify default behaviors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are making good progress! My kids are waking up as I completed the review of the R/
code, so I didn't have a chance to review the tests yet. Please take a look at these and let me know what you think.
R/intervals_support_funs.R
Outdated
|
||
#' @export | ||
interval_remove_impute.PKNCAdata <- function(data, target_impute, target_params = NULL, target_groups = NULL, impute_column = NULL, new_rows_after_original = TRUE) { | ||
if (is.null(impute_column) && !is.na(data$impute)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For removing impute, please have this behave differently than adding impute. If impute is given via data$impute
please only remove from there rather than creating a column.
I think that default behavior of the new rows showing up immediately after the original rows should be fine. I don't think that we need to control sort order for the users more than that (if they want to manage the sort order, then they can do that with other R tools rather than building it into PKNCA). I don't see a use case where we would want duplicated imputation methods. Can you think of one? If so, we can keep those options. If not, we should not add the feature. |
@billdenney I had the same thought but wasn’t sure. However, what do you think the default behavior should be? My concern is that if the user specifies an existing impute for an integer position and we don’t allow duplication, it’s unclear whether or not the default behavior should replace the original impute—and if so, where (should the |
I think that we should remove imputation first when duplicated and then put it at the location requested. In general, the imputation method order should not cause conflict in real cases. The different imputation methods will modify different parts of the curve (usually the |
…instead of NAs) Co-Authored-By: Bill Denney <billdenney@users.noreply.github.com>
Hopefully now it is better @billdenney ! Some comments on the implementation:
Let me know your thoughts, hopefully we are getting closer to the solution! 😉 |
…in after (do not split rows)
Contributes to solve #379
New interval supporting functions acting to add/remove imputations from the impute column in
PKNCAdata$intervals
Add imputation
interval_add_impute(data, target_impute, after = Inf, target_params = NULL, target_groups = NULL)
impute is the imputation character string to add, matching the behavior of PKNCAdata()
after follows similar behavior to the after argument of base::append(); 0 indicates it will be added as the first imputation method; Inf (or any number greater than the number of methods currently specified) indicates that it will be added as the last imputation method;
If there is already an imputation:
the imputation will be separated by commas (i.e. strsplit(current_impute, split = "[, ]"))
the new imputation will be added at the correct place (defined by after), and
The final imputation method will be put back together separated by commas (i.e. vapply(X = new_impute, FUN = paste, collapse = ",", FUN.VALUE = ""))
Remove imputation
interval_remove_impute(data, target_impute, target_params = NULL, target_groups = NULL)
split any imputation from the intervals and remove it
warn if the imputation was not found in any of the intervals