Skip to content

Commit

Permalink
add OMEGA and SIGMA block info to ext pars output
Browse files Browse the repository at this point in the history
  • Loading branch information
philipdelff committed Aug 15, 2024
1 parent ab3425b commit 29d26ff
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: NMdata
Type: Package
Title: Preparation, Checking and Post-Processing Data for PK/PD Modeling
Version: 0.1.6.915
Version: 0.1.6.921
Authors@R:
c(person(given="Philip", family="Delff",
email = "philip@delff.dk",
Expand Down
22 changes: 22 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

# 0.1.7

## New features
* `NMreadPartab()` has been generalized to support comment formats very
generally. `NMreadPartab()` reads the comments in `$THETA`, `$OMEGA`
Expand All @@ -24,6 +25,27 @@
* `mergeCheck()` has additional features available in the common.cols
argument.

* `NMreadExt()` separates objective function values into a separate list
element. The `return` argument is used to control what data to
retrieve. Use one of "pars" (default, parameter estimates),
"iterations" (parameter estimates for each iteration), "obj" for
objective funtion value, or "all" for a list with all of those.

* `NMreadExt()` adds block information to `OMEGA` and `SIGMA` elements
based on off-diagonal values.

* `NMreadExt()` adds a `par.name` column which is provides consistent
parameter naming. Instead of Nonmem's `THETA1` which is found in the
`parameter` column, the `par.name` column will contain `THETA(1)`
consistent with the `OMEGA` and `SIGMA` naming like `OMEGA(1,1)`

* `NMreadExt()` recognizes Laplacian estimation steps in addition to
the already supported FO, FOCE(i), SAEM, and IMP.

* A new option `nc` can be controlled with NMdataConf(). This is to
serve `NMsim`. Please see `NMsim::NMexec`. `NMsim::NMsim()` does not
adhere to this setting because it does not parallellize by default.

## Bugfixes
* `NMscanInput()` and `NMreadCsv()` could fail if file names had no
extensions. Fixed.
Expand Down
22 changes: 19 additions & 3 deletions R/NMreadExt.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
##' \code{return="pars"} (default) the final estimates are
##' returned in addition to what other parameter-level information
##' is found, like FIX, sd etc. as columns. If
##' \code{return="iterations"}, the iterations are returned. If
##' \code{return="iterations"}, the iterations are returned
##' (including objective function value). If \code{return="obj"}
##' objective function value at final estimate is returned. If
##' \code{return="all"}, all er returned, though in separate
##' data.frames compiled in a list.
##' @param as.fun The default is to return data as a data.frame. Pass
Expand Down Expand Up @@ -121,7 +123,7 @@ NMreadExt <- function(file,return,as.fun,modelname,col.model,auto.ext,tableno="m

if(missing(return)||is.null(return)) return <- "pars"
return <- tolower(return)

allowed.return <- c("pars","iterations","obj","all")
if(!return %in% allowed.return){
stop("Argument return has to be one of: ", paste(allowed.return,collapse =", "))
Expand Down Expand Up @@ -195,12 +197,26 @@ NMreadExt <- function(file,return,as.fun,modelname,col.model,auto.ext,tableno="m
obj[,(cols.drop):=NULL]
pars <- pars[!parameter%in%c("SAEMOBJ","OBJ")]

### this setorder call doesnt work - unsure why
### this setorder call doesnt work - unsure why
## setorder(pars,match(par.type,c("THETA","OMEGA","SIGMA")),i,j)
pars <- pars[order(model,match(par.type,c("THETA","OMEGA","SIGMA")),i,j)]
## est is just a copy of value for backward compatibility
pars[,est:=value]

### add OMEGA block information based on off diagonal values
tab.blocks <- rbind(pars[par.type%in%c("OMEGA","SIGMA"),.(par.type,i=i,j=j,value)],
pars[par.type%in%c("OMEGA","SIGMA"),.(par.type,i=j,j=i,value)])[
abs(value)>1e-9,.(iblock=min(i,j),blocksize=max(abs(j-i))+1),by=.(par.type,i)]

tab.blocks

pars <- mergeCheck(pars,tab.blocks,by=cc(par.type,i),all.x=T)
pars[abs(i-j)>(blocksize-1),(c("iblock","blocksize")):=list(NA,NA)]

pars[par.type%in%c("OMEGA","SIGMA")&i==j&is.na(iblock),iblock:=i]
pars[par.type%in%c("OMEGA","SIGMA")&i==j&iblock==i,blocksize:=1]
### done add OMEGA/SIGMA blocks

}

## what to do about OBJ? Disregard? And keep in a iteration table instead?
Expand Down

0 comments on commit 29d26ff

Please sign in to comment.