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

Interval support functions #379

Open
billdenney opened this issue Jan 30, 2025 · 3 comments
Open

Interval support functions #379

billdenney opened this issue Jan 30, 2025 · 3 comments

Comments

@billdenney
Copy link
Owner

Based on the conversation in #371, we need a set of interval-support functions. Some of the needs are:

  • Drop some/all parameters being calculated (be sure that there is an option for exceptions for specific parameters)
  • Add parameters to calculate
  • Add or remove imputation

The initial interface that I'm thinking of is:

All functions

The data input argument can be either

  • a data.frame that specifies the intervals
  • A PKNCAdata object (or something that can be coerced into a PKNCAdata object)

Drop parameters

interval_remove_param(data, param = NULL, param_pattern = NULL)

  • param is a character vector of parameters to remove
  • param_pattern is a character vector (can be more than one pattern) of regular expression patterns of parameters to remove

One or both of param or param_pattern must be given.

Sets all parameters matching param or param_pattern to TRUE.

Add param

It's not clear to me that this is necessary since you can simply set the column to TRUE. But, we can include it for completeness of the interface and the fact that it's trivial.

interval_add_param(data, param = NULL, param_pattern = NULL)

Arguments are the same as interval_remove_param().

Sets all parameters matching param or param_pattern to FALSE.

Add imputation

interval_add_impute(data, impute, after = Inf)

  • 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, impute)

  • split any imputation from the intervals and remove it
  • warn if the imputation was not found in any of the intervals
@Gero1999
Copy link
Contributor

Gero1999 commented Feb 1, 2025

Hey @billdenney I think this issue was accidentally duplicated, see #378

Also I think that it would be nice to have other optional parameters, specially in interval_add_impute and interval_remove_impute. In our discussion in #371, my problem is that I only wanted to eliminate the imputation for some parameters but not for others. Therefore I would suggest adding a parameter specification over which ones the action applies (e.g, target_params = c("cmax", "tmax")) and perhaps also a filtering argument that can allow you to be more specific over which intervals the action applies (i.e, target_intervals = list(ANALYTE = "Analyte1", ROUTE = "intravascular")).

@billdenney
Copy link
Owner Author

GitHub was having issues with issues yesterday. Thanks for pointing out the duplication. I closed the other.

The way I was thinking this would fix your issue is that you could do something like the following.

d_intervals_prep <- data.frame(start = 0, end = Inf, cmax = TRUE, tmax = TRUE, auclast = TRUE, impute = "start_logslope")
d_intervals_noimpute <- d_intervals_prep |> filter(cmax) |> interval_remove_param(param_pattern ="*") |> mutate(impute = NA_character_, cmax = TRUE)

... But, as I look at that, it's indirect.

Let's implement the above functions as support functions for ones that do more detailed controls. (I prefer smaller, more focused functions as they are easier to maintain.)

@Gero1999
Copy link
Contributor

Gero1999 commented Feb 5, 2025

Hello @billdenney thanks! I made already some interval_add_impute & interval_remove_impute draft functions (they are already functional!). I added the interval specification arguments as optional. Feel free to give them a quick look and ask for modifications or changes in the pr #384.

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