Skip to content

Commit

Permalink
addOmegaCorr is adding corr of sigmas too
Browse files Browse the repository at this point in the history
  • Loading branch information
philipdelff committed Jan 18, 2025
1 parent fed5afc commit 4791693
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 8 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.8.941
Version: 0.1.8.942
Authors@R:
c(person(given="Philip", family="Delff",email = "[email protected]",role = c("aut", "cre")),
person("Brian", "Reilly", email = "[email protected]",role = c("ctb")),
Expand Down
28 changes: 23 additions & 5 deletions R/addOmegaCorr.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
##' add Omega correlations to a parameter table

##' @param pars A parameter table, like returned by `NMreadExt()`.
##' @param by The name of a column, as a string. Calculate the
##' correlations within a grouping variable? This will often be a
Expand Down Expand Up @@ -42,11 +41,30 @@ addOmegaCorr <- function(pars,by=NULL,as.fun,col.value="value"){
res.list <- lapply(
pars.list,
function(x){
Sigma <- dt2mat(x[par.type=="OMEGA"],col.value=col.value)
mat.cor <- suppressWarnings(cov2cor(Sigma))
dt.cor <- mat2dt(mat.cor,triangle="all")

x.omega <- x[par.type=="OMEGA"]
dt.cor <- NULL
if(nrow(x.omega)){
Sigma <- dt2mat(x.omega,col.value=col.value)
mat.cor <- suppressWarnings(cov2cor(Sigma))
dt.cor.1 <- mat2dt(mat.cor,triangle="all",as.fun="data.table")[,par.type:="OMEGA"]
##x <- mergeCheck(x,dt.cor[,.(par.type="OMEGA",i,j,corr=get(col.value))],by=cc(par.type,i,j),all.x=TRUE,quiet=TRUE)
dt.cor <- rbind(dt.cor,dt.cor.1)
}

x <- mergeCheck(x,dt.cor[,.(par.type="OMEGA",i,j,corr=get(col.value))],by=cc(par.type,i,j),all.x=TRUE)
x.sigma <- x[par.type=="SIGMA"]
if(nrow(x.sigma)){
Sigma <- dt2mat(x.sigma,col.value=col.value)
mat.cor <- suppressWarnings(cov2cor(Sigma))
dt.cor.1 <- mat2dt(mat.cor,triangle="all",as.fun="data.table")[,par.type:="SIGMA"]
## x <- mergeCheck(x,dt.cor[,.(par.type="SIGMA",i,j,corr=get(col.value))],by=cc(par.type,i,j),all.x=TRUE,quiet=TRUE)
dt.cor <- rbind(dt.cor,dt.cor.1)
}
if(!is.null(dt.cor)){
dt.cor <- dt.cor[,.(par.type,i,j,corr=get(col.value))]
dt.cor[is.nan(corr),corr:=0]
x <- mergeCheck(x,dt.cor,by=cc(par.type,i,j),all.x=TRUE,quiet=TRUE)
}
x
})

Expand Down
4 changes: 2 additions & 2 deletions man/NMreadSection.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added tests/testthat/testReference/NMcheckData_22.rds
Binary file not shown.
Binary file added tests/testthat/testReference/NMwriteSection_08.rds
Binary file not shown.
Binary file added tests/testthat/testReference/addOmegaCorr_01.rds
Binary file not shown.
Binary file added tests/testthat/testReference/compareCols_06.rds
Binary file not shown.
16 changes: 16 additions & 0 deletions tests/testthat/test_addOmegaCorr.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
library(data.table)
context("addOmegaCorr")

test_that("basic",{

fileRef <- "testReference/addOmegaCorr_01.rds"
file.mod <- "testData/nonmem/xgxr022.mod"

ext <- NMreadExt(file.mod)

res1 <- addOmegaCorr(ext)

res1
expect_equal_to_reference(res1,fileRef)

})

0 comments on commit 4791693

Please sign in to comment.