Skip to content

Commit

Permalink
Merge pull request #367 from nlmixr2/fix-366
Browse files Browse the repository at this point in the history
Fix 366
  • Loading branch information
mattfidler authored Jun 23, 2023
2 parents 42589c5 + 3dd6939 commit b6459ab
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 21 deletions.
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
- Printing models with correlated omega values and omega values fixed
to zero no longer fails (#359)

- Values in `$parFixed` for BSV without exponential transformation are now
correctly shown (#366)

# nlmixr2est 2.1.6

## Breaking changes
Expand All @@ -25,7 +28,7 @@

- `augPred()` now consistently uses the simulation model (instead of
the inner model used for `CWRES` calculation).

## Other changes

- Dropped dependence on orphaned package `ucminf`
Expand Down
45 changes: 25 additions & 20 deletions R/nlmixr2output.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#' This applies the manually specified back-transformations
#'
#' @param .ret focei environment
#' @return Nothing, called for side effecs
#' @return Nothing, called for side effects
#' @author Matthew L. Fidler
#' @noRd
.updateParFixedApplyManualBacktransformations <- function(.ret, .ui) {
Expand Down Expand Up @@ -91,36 +91,41 @@
#' @param .env Environment where the indicators of `.sdOnly`, `.cvOnly` are stored so the column name can be changed to match the data
#' @param .ome Omega fixed vector
#' @param .muRefCurEval The current mu ref evaluation. This determines if the ETA is logit normal and %CV should be calculated.
#' @param .sigdig is the number of significant digits used in the evaulation
#' @return Data frame row with ch= the charaacter representation and v is the vector representation of the CV or sd
#' @author Matthew L. Fidler
#' @param .sigdig is the number of significant digits used in the evaluation
#' @return Data frame row with ch= the character representation and v is the vector representation of the CV or sd
#' @author Matthew L. Fidler and Bill Denney
#' @noRd
.updateParFixedGetEtaRow <- function(.eta, .env, .ome, .omegaFix, .muRefCurEval, .sigdig) {
.v <- .ome[.eta, .eta]
.w <- which(.muRefCurEval$parameter == .eta)
if (.muRefCurEval$curEval[.w] == "exp") {
assign(".sdOnly", FALSE, envir=.env)
return(data.frame(
ch = paste0(
ifelse(.omegaFix[.eta], "fix(", ""),
formatC(signif(sqrt(exp(.v) - 1) * 100, digits = .sigdig),
digits = .sigdig, format = "fg", flag = "#"),
ifelse(.omegaFix[.eta], ")", "")
),
v = sqrt(exp(.v) - 1) * 100))
.valNumber <- sqrt(exp(.v) - 1) * 100
.valCharPrep <- .valNumber
} else {
assign(".cvOnly", FALSE, envir=.env)
return(data.frame(
ch = paste0(
ifelse(.omegaFix[.eta], "fix(", ""),
formatC(signif(sqrt(.w), digits = .sigdig),
digits = .sigdig, format = "fg", flag = "#"),
ifelse(.omegaFix[.eta], ")", "")),
v = .v))
.valNumber <- .v
.valCharPrep <- sqrt(.v)
}
if (.omegaFix[.eta]) {
.charPrefix <- "fix("
.charSuffix <- ")"
} else {
.charPrefix <- ""
.charSuffix <- ""
}
.valChar <-
formatC(
signif(.valCharPrep, digits = .sigdig),
digits = .sigdig, format = "fg", flag = "#"
)
data.frame(
ch = paste0(.charPrefix, .valChar, .charSuffix),
v = .valNumber
)
}

#' This will add the between subject varaibility to the mu-referenced theta. It also expands the table to include non-mu referenced ETAs
#' This will add the between subject variability to the mu-referenced theta. It also expands the table to include non-mu referenced ETAs
#'
#'
#' @param .ret The focei return environment
Expand Down
29 changes: 29 additions & 0 deletions tests/testthat/test-nlmixr2output.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
test_that(".updateParFixedGetEtaRow returns correct values", {
envPrep <- new.env()
expect_equal(
.updateParFixedGetEtaRow(
.eta = "iivemax",
.env = envPrep,
.ome = matrix(25, nrow = 1, dimnames = list("iivemax", "iivemax")),
.omegaFix = c(iivemax = FALSE),
.muRefCurEval = data.frame(parameter = "iivemax", curEval = "", low = NA_real_, hi = NA_real_),
.sigdig = 3L
),
data.frame(ch = "5.00", v = 25)
)
expect_false(envPrep$.cvOnly)

envPrep <- new.env()
expect_equal(
.updateParFixedGetEtaRow(
.eta = "iivemax",
.env = envPrep,
.ome = matrix(0.4, nrow = 1, dimnames = list("iivemax", "iivemax")),
.omegaFix = c(iivemax = FALSE),
.muRefCurEval = data.frame(parameter = "iivemax", curEval = "exp", low = NA_real_, hi = NA_real_),
.sigdig = 3L
),
data.frame(ch = "70.1", v = sqrt(exp(0.4) - 1) * 100)
)
expect_false(envPrep$.sdOnly)
})

0 comments on commit b6459ab

Please sign in to comment.