UUPharmacometrics / xpose

Graphical diagnostics for pharmacometric models
https://uupharmacometrics.github.io/xpose
GNU Lesser General Public License v3.0
55 stars 28 forks source link

Feature Request: Simplify Recoding Parameters #117

Closed billdenney closed 6 years ago

billdenney commented 6 years ago

Within NONMEM, parameters must be numbered, but it would help if we could recode parameters within xpose either by merging with a list of mapping data.frames or by running recode on the data.

As an example, SEX = 1 isn't very informative while SEX = "Female" or SEX = "Male" is (https://uupharmacometrics.github.io/xpose/articles/customize_plots.html#modify-aesthetics).

A simple implementation may make a method for the dplyr::recode() function that would apply to xpdb objects that would also take a column name.

billdenney commented 6 years ago

This may be possible with something like the following:

recode.xpose_data <- function(.x, ..., .column, .default=NULL, .missing=NULL) {
  for (data_idx in seq_along(.x$data$data)) {
    if (.column %in% names(.x$data$data[[data_idx]])) {
      .x$data$data[[data_idx]][[.column]] <-
        recode(.x$data$data[[data_idx]][[.column]], ..., .default=.default, .missing=.missing)
    } else {
      warning("Column ", .column, " does not exist in data for problem ", data_idx)
    }
  }
  .x
}
bguiastr commented 6 years ago

@billdenney recode() can be used in xpose isn't this what you are trying to achieve?

xpdb_ex_pk %>% 
  mutate(SEX = dplyr::recode(SEX, `1` = 'Male', `2` = "Female")) %>% 
  dv_vs_ipred(type = 'p', aes(point_color = SEX))

example

billdenney commented 6 years ago

That's exactly it! I didn't realize that mutate worked with xpose (I missed it in the docs; my oversight).

bguiastr commented 6 years ago

No problem!