Closed mattfidler closed 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.
You could see if it is the xml file where the error occurs by:
xmlInfo <- nmxml("run502.xml")
xmlInfo <- nmxml("run502.xml") xmlInfo NULL
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:
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
to16.9184465874669
ℹ change initial estimate oftheta2
to29.0692797324232
ℹ change initial estimate oftheta3
to2.43235177034855
ℹ change initial estimate oftheta4
to1.34653279917032
ℹ change initial estimate oftheta5
to0.304490361221458
ℹ change initial estimate oftheta6
to2.5
ℹ some correlations may have been dropped for the variables:eta1
,eta2
ℹ the piping should specify the needed covariances directly ℹ change initial estimate ofeta1
to0.0722553408614083
ℹ add covariance betweeneta2
andeta1
with initial estimate0.0650039024597345
ℹ change initial estimate ofeta2
to0.0700334194752202
ℹ some correlations may have been dropped for the variables:eta3
,eta4
ℹ the piping should specify the needed covariances directly ℹ change initial estimate ofeta3
to0.16268513883389
ℹ add covariance betweeneta4
andeta3
with initial estimate0.0352032351476214
ℹ change initial estimate ofeta4
to0.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
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
to16.9184465874669
ℹ change initial estimate oftheta2
to29.0692797324232
ℹ change initial estimate oftheta3
to2.43235177034855
ℹ change initial estimate oftheta4
to1.34653279917032
ℹ change initial estimate oftheta5
to0.304490361221458
ℹ change initial estimate oftheta6
to2.5
ℹ some correlations may have been dropped for the variables:eta1
,eta2
ℹ the piping should specify the needed covariances directly ℹ change initial estimate ofeta1
to0.0722553408614083
ℹ add covariance betweeneta2
andeta1
with initial estimate0.0650039024597345
ℹ change initial estimate ofeta2
to0.0700334194752202
ℹ some correlations may have been dropped for the variables:eta3
,eta4
ℹ the piping should specify the needed covariances directly ℹ change initial estimate ofeta3
to0.16268513883389
ℹ add covariance betweeneta4
andeta3
with initial estimate0.0352032351476214
ℹ change initial estimate ofeta4
to0.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.
@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
run502cov.zip Here is the zip file containing the .cov.
Thanks @sliao999
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'))
Let me know.
Dear Matt, The error was resolved. Thanks.
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.
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.
Originally posted by @sliao999 in https://github.com/nlmixr2/nonmem2rx/issues/125#issuecomment-1591785296