nlmixr2 / nonmem2rx

nonmem2rx
https://nlmixr2.github.io/nonmem2rx/
9 stars 0 forks source link

`lotri` issue #142

Closed mattfidler closed 1 year ago

mattfidler commented 1 year ago

This can be a very useful R package for our modeling work. However, I tried to use it for two of the nonmem mod files, and none of them work. Error occurred and I have no way to resolve these issues. For example, the last issue I got this.

mod <- nonmem2rx("run502.mod")
ℹ getting information from 'run502.mod'
ℹ reading in xml file
lotri syntax error:
================================================================================
lotri error:
lower triangular matrix not correct size
did you mean something like:
theta1 + theta2 + theta3 + theta4 + theta5 + theta6 + theta7 + theta8 + theta9 + theta10 + theta11 + theta12 + theta13 + eta1 + omega.1.2 + omega.1.3 + omega.1.4 + omega.1.5 + omega.1.6 + omega.1.7 + omega.1.8 + omega.1.9 + omega.1.10 + omega.1.11 + omega.1.12 + eta2 + omega.2.3 + omega.2.4 + omega.2.5 + omega.2.6 + omega.2.7 + omega.2.8 + omega.2.9 + omega.2.10 + omega.2.11 + omega.2.12 + eta3 + omega.3.4 + omega.3.5 + omega.3.6 + omega.3.7 + omega.3.8 + omega.3.9 + omega.3.10 + omega.3.11 + omega.3.12 + eta4 + omega.4.5 + omega.4.6 + omega.4.7 + omega.4.8 + omega.4.9 + omega.4.10 + omega.4.11 + omega.4.12 + eta5 + omega.5.6 + omega.5.7 + omega.5.8 + omega.5.9 + omega.5.10 + omega.5.11 + omega.5.12 + eta6 + omega.6.7 + omega.6.8 + omega.6.9 + omega.6.10 + omega.6.11 + omega.6.12 + eta7 + omega.7.8 + omega.7.9 + omega.7.10 + omega.7.11 + omega.7.12 + eta8 + omega.8.9 + omega.8.10 + omega.8.11 + omega.8.12 + eta9 + omega.9.10 + omega.9.11 + omega.9.12 + eta10 + omega.10.11 + omega.10.12 + eta11 + omega.11.12 + eta12 + eps1+v1+v2+v3+v4+v5+v6+v7+v8+v9+v10+v11+v12+v13+v14+v15+v16+v17+v18+v19+v20+v21+v22+v23+v24+v25+v26+v27~c(1.30441367197642,

Originally posted by @sliao999 in https://github.com/nlmixr2/nonmem2rx/issues/125#issuecomment-1591785296

mattfidler commented 1 year ago

Hi @sliao999

This appears to have problems importing the covariance matrix from NONMEM.

I'm unsure where it is trying to import this from, though I believe it tries to use the xml file as the source of the data first.

Let me see if I can gracefully handle this condition, though it is much harder because I do not have a reproducible example to work with.

mattfidler commented 1 year ago

You could see if it is the xml file where the error occurs by:

xmlInfo <- nmxml("run502.xml")
sliao999 commented 1 year ago

xmlInfo <- nmxml("run502.xml") xmlInfo NULL

sliao999 commented 1 year ago

Need to change the working directory, Now I got the same error as before.

setwd("E:\MicuRX\poppk1\run502.nm7")

xmlInfo <- nmxml("run502.xml") lotri syntax error:

lotri error: lower triangular matrix not correct size did you mean something like:

sliao999 commented 1 year ago

It seems to be problem from between-occasion variability (BOV) in this mod file. When I tried the same model without BOV, this error went away. However, I got other problem. 'alag(.)'/'rate(.)'/'dur(.)' None of these parameters were defined in this mod.

setwd("E:\MicuRX\poppk1\run401f.nm7") mod <- nonmem2rx("run401f.mod") ℹ getting information from 'run401f.mod' ℹ reading in xml file ℹ done ℹ reading in phi file ℹ done ℹ reading in lst file ℹ abbreviated list parsing ℹ done ℹ done ℹ splitting control stream by records ℹ done ℹ Processing record $INPUT ℹ Processing record $MODEL ℹ Processing record $THETA ℹ Processing record $OMEGA ℹ Processing record $SIGMA ℹ Processing record $PROBLEM ℹ Processing record $DATA ℹ Processing record $SUBROUTINES ℹ Processing record $PK ℹ Processing record $DES ℹ Processing record $ERROR ℹ Processing record $ESTIMATION ℹ Ignore record $ESTIMATION ℹ Processing record $COVARIANCE ℹ Ignore record $COVARIANCE ℹ Processing record $TABLE ℹ change initial estimate of theta1 to 16.9184465874669 ℹ change initial estimate of theta2 to 29.0692797324232 ℹ change initial estimate of theta3 to 2.43235177034855 ℹ change initial estimate of theta4 to 1.34653279917032 ℹ change initial estimate of theta5 to 0.304490361221458 ℹ change initial estimate of theta6 to 2.5 ℹ some correlations may have been dropped for the variables: eta1, eta2 ℹ the piping should specify the needed covariances directly ℹ change initial estimate of eta1 to 0.0722553408614083 ℹ add covariance between eta2 and eta1 with initial estimate 0.0650039024597345 ℹ change initial estimate of eta2 to 0.0700334194752202 ℹ some correlations may have been dropped for the variables: eta3, eta4 ℹ the piping should specify the needed covariances directly ℹ change initial estimate of eta3 to 0.16268513883389 ℹ add covariance between eta4 and eta3 with initial estimate 0.0352032351476214 ℹ change initial estimate of eta4 to 0.376883716036017 ℹ read in nonmem input data (for model validation): E:\MicuRX\poppk1\nm1.csv ℹ ignoring lines that begin with 'C' ℹ applying names specified by $INPUT ℹ subsetting accept/ignore filters code: .data[-which((.data$FLAG == 1 | .data$FED == 0)),] ℹ done ℹ read in nonmem IPRED data (for model validation): E:\MicuRX\poppk1\run401f.nm7\run401f.fit ℹ done ℹ changing most variables to lower case ℹ done ℹ replace theta names ℹ done ℹ replace eta names ℹ done ℹ renaming compartments ℹ done ℹ solving ipred problem Error : 'alag(.)'/'rate(.)'/'dur(.)' cannot depend on the state values ℹ done ℹ solving pred problem Error : 'alag(.)'/'rate(.)'/'dur(.)' cannot depend on the state values

mattfidler commented 1 year ago

It seems to be problem from between-occasion variability (BOV) in this mod file. When I tried the same model without BOV, this error went away.

However, I got other problem. 'alag(.)'/'rate(.)'/'dur(.)' None of these parameters were defined in this mod.

setwd("E:\MicuRX\poppk1\run401f.nm7") mod <- nonmem2rx("run401f.mod") ℹ getting information from 'run401f.mod' ℹ reading in xml file ℹ done ℹ reading in phi file ℹ done ℹ reading in lst file ℹ abbreviated list parsing ℹ done ℹ done ℹ splitting control stream by records ℹ done ℹ Processing record $INPUT ℹ Processing record $MODEL ℹ Processing record $THETA ℹ Processing record $OMEGA ℹ Processing record $SIGMA ℹ Processing record $PROBLEM ℹ Processing record $DATA ℹ Processing record $SUBROUTINES ℹ Processing record $PK ℹ Processing record $DES ℹ Processing record $ERROR ℹ Processing record $ESTIMATION ℹ Ignore record $ESTIMATION ℹ Processing record $COVARIANCE ℹ Ignore record $COVARIANCE ℹ Processing record $TABLE ℹ change initial estimate of theta1 to 16.9184465874669 ℹ change initial estimate of theta2 to 29.0692797324232 ℹ change initial estimate of theta3 to 2.43235177034855 ℹ change initial estimate of theta4 to 1.34653279917032 ℹ change initial estimate of theta5 to 0.304490361221458 ℹ change initial estimate of theta6 to 2.5 ℹ some correlations may have been dropped for the variables: eta1, eta2 ℹ the piping should specify the needed covariances directly ℹ change initial estimate of eta1 to 0.0722553408614083 ℹ add covariance between eta2 and eta1 with initial estimate 0.0650039024597345 ℹ change initial estimate of eta2 to 0.0700334194752202 ℹ some correlations may have been dropped for the variables: eta3, eta4 ℹ the piping should specify the needed covariances directly ℹ change initial estimate of eta3 to 0.16268513883389 ℹ add covariance between eta4 and eta3 with initial estimate 0.0352032351476214 ℹ change initial estimate of eta4 to 0.376883716036017 ℹ read in nonmem input data (for model validation): E:\MicuRX\poppk1\nm1.csv ℹ ignoring lines that begin with 'C' ℹ applying names specified by $INPUT ℹ subsetting accept/ignore filters code: .data[-which((.data$FLAG == 1 | .data$FED == 0)),] ℹ done ℹ read in nonmem IPRED data (for model validation): E:\MicuRX\poppk1\run401f.nm7\run401f.fit ℹ done ℹ changing most variables to lower case ℹ done ℹ replace theta names ℹ done ℹ replace eta names ℹ done ℹ renaming compartments ℹ done ℹ solving ipred problem Error : 'alag(.)'/'rate(.)'/'dur(.)' cannot depend on the state values ℹ done ℹ solving pred problem Error : 'alag(.)'/'rate(.)'/'dur(.)' cannot depend on the state values

This issue is captured in #143, and seems to be a separate issue to me. You have confirmed that reading the xml file gives the same error.

mattfidler commented 1 year ago

@sliao999

If you think you can send the covariance from the xml maybe I can fix this correctly (not the rest of the xml)

I have created a debugging function that is in the pull request #144 that could do that for you.

However, you do not need to wait for it to extract the covariance, you can use the code directly

setwd("E:\MicuRX\poppk1\run502.nm7")
nmxmlCov <- function(xml, xmlout, tag="//nm:covariance") {
  .xml <- try(xml2::read_xml(xml), silent=TRUE)
  if (inherits(.xml, "try-error")) return(NULL)
  .covXml <- xml2::xml_find_first(.xml,"//nm:covariance")
  xml2::write_xml(.covXml, xmlout)
  message("written to xml output '", xmlout, "'")
  invisible()
}
nmxmlCov("run502.xml", "run502cov.xml")

Then the file run502cov.xml will include only the covariance information from the xml file (please open it to verify). The actual run information (other than the covariance) would be lost and not be queryable, so it should protect the model structure and the data itself if shared.

If you think this is something that can be shared in the open source space, then please zip it and attach it to this issue, and I can test against the issue to possibly fix it for you.

In the mean time, I am working through a method to downgrade the more accurate xml covariance information to information that comes from the .cov file

sliao999 commented 1 year ago

run502cov.zip Here is the zip file containing the .cov.

mattfidler commented 1 year ago

Thanks @sliao999

mattfidler commented 1 year ago

Hi @sliao999

The development version of nonmem2rx could probably fix this issue (though unclear about #143)

You can install it with r-universe by:

# Install nonmem2rx in R:
install.packages('nonmem2rx', repos = c('https://nlmixr2.r-universe.dev', 'https://cloud.r-project.org'))
mattfidler commented 1 year ago

Let me know.

sliao999 commented 1 year ago

Dear Matt, The error was resolved. Thanks.

mattfidler commented 1 year ago

Great @sliao999

I will close #143 for now, since I cannot reproduce it or fix it without a reproducible example.

If you have an open source model this occurs on, I can try to work through this too.