Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Factor value that is part of keep is converted to numeric in the source data #78

Closed
billdenney opened this issue Sep 26, 2023 · 6 comments · Fixed by #79
Closed

Factor value that is part of keep is converted to numeric in the source data #78

billdenney opened this issue Sep 26, 2023 · 6 comments · Fixed by #79

Comments

@billdenney
Copy link
Contributor

d_sim$TRTG should not be modified, but in the first pass where it is part of keep, it is. (My guess is that this will end up being an rxode2 issue, but I'm not sure exactly where keep has its effects at the moment, and I want to put the reprex into the record.)

library(nlmixr2est)
#> Loading required package: nlmixr2data

one.compartment <- function() {
  ini({
    tka <- 0.45; label("Ka")
    tcl <- 1; label("Cl")
    tv <- 3.45; label("V")
    eta.ka ~ 0.6
    eta.cl ~ 0.3
    eta.v ~ 0.1
    add.sd <- 0.7
  })
  model({
    ka <- exp(tka + eta.ka)
    cl <- exp(tcl + eta.cl)
    v <- exp(tv + eta.v)
    d/dt(depot) = -ka * depot
    d/dt(center) = ka * depot - cl / v * center
    cp = center / v
    cp ~ add(add.sd)
  })
}

d_sim <- theo_sd
d_sim$TRTG <- ordered(ifelse(theo_sd$WT < median(theo_sd$WT), "Low", "High"))
d_sim$TRTG
#>   [1] High High High High High High High High High High High High High High High
#>  [16] High High High High High High High High High High High High High High High
#>  [31] High High High High High High High High High High High High High High High
#>  [46] High High High Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  Low 
#>  [61] High High High High High High High High High High High High Low  Low  Low 
#>  [76] Low  Low  Low  Low  Low  Low  Low  Low  Low  High High High High High High
#>  [91] High High High High High High High High High High High High High High High
#> [106] High High High Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  Low 
#> [121] Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  Low 
#> [136] Low  Low  Low  Low  Low  Low  Low  Low  Low 
#> Levels: High < Low
fit <- nlmixr2(one.compartment, d_sim, est="rxSolve", list(keep = "TRTG"))
d_sim$TRTG
#>   [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
#>  [38] 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 2 2
#>  [75] 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2
#> [112] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2

d_sim <- theo_sd
d_sim$TRTG <- ordered(ifelse(theo_sd$WT < median(theo_sd$WT), "Low", "High"))
fit <- nlmixr2(one.compartment, d_sim, est="rxSolve")
d_sim$TRTG
#>   [1] High High High High High High High High High High High High High High High
#>  [16] High High High High High High High High High High High High High High High
#>  [31] High High High High High High High High High High High High High High High
#>  [46] High High High Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  Low 
#>  [61] High High High High High High High High High High High High Low  Low  Low 
#>  [76] Low  Low  Low  Low  Low  Low  Low  Low  Low  High High High High High High
#>  [91] High High High High High High High High High High High High High High High
#> [106] High High High Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  Low 
#> [121] Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  Low 
#> [136] Low  Low  Low  Low  Low  Low  Low  Low  Low 
#> Levels: High < Low

Created on 2023-09-25 with reprex v2.0.2

@billdenney
Copy link
Contributor Author

With a quick additional test, it seems like this only has an effect when nStud = 1 (the default) and not when nStud = 1000.

@mattfidler mattfidler transferred this issue from nlmixr2/nlmixr2est Dec 5, 2023
@mattfidler
Copy link
Member

d_sim$TRTG will be modified since there are dosing records that will be inserted and interpolations that will be performed.

But there should be no effects on the source data.

@mattfidler
Copy link
Member

library(rxode2)
#> rxode2 2.0.14.9000 using 8 threads (see ?getRxThreads)
#>   no cache: create with `rxCreateCache()`

one.compartment <- function() {
ini({
    tka <- 0.45; label("Ka")
    tcl <- 1; label("Cl")
    tv <- 3.45; label("V")
    eta.ka ~ 0.6
    eta.cl ~ 0.3
    eta.v ~ 0.1
    add.sd <- 0.7
    })
model({
      ka <- exp(tka + eta.ka)
      cl <- exp(tcl + eta.cl)
      v <- exp(tv + eta.v)
      d/dt(depot) = -ka * depot
      d/dt(center) = ka * depot - cl / v * center
      cp = center / v
      cp ~ add(add.sd)
      })
}

d_sim <- nlmixr2data::theo_sd
d_sim$TRTG <- ordered(ifelse(nlmixr2data::theo_sd$WT < median(nlmixr2data::theo_sd$WT), "Low", "High"))
summary(d_sim$TRTG)
#> High  Low 
#>   84   60

fit <- rxSolve(one.compartment, d_sim, keep="TRTG")

summary(d_sim$TRTG)
#>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
#>   1.000   1.000   1.000   1.417   2.000   2.000

Created on 2023-12-04 with reprex v2.0.2

@mattfidler

This comment was marked as outdated.

@mattfidler

This comment was marked as outdated.

@mattfidler
Copy link
Member

So currently in keep:

  • Standard factors are supported
  • Standard logical vectors are supported
  • Standard character vectors are supported
  • Standard integer vectors are supported

Any sort of attributes will be dropped (maybe should have some sort of warning but would need to explicitly check for attributes).

Could additionally support ordered factors

@mattfidler mattfidler linked a pull request Dec 5, 2023 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants