qPharmetra / qpToolkit

Tools for population PK modeling, visualization, and reporting
Other
1 stars 1 forks source link

get.shrinkage() breaks with NONMEM 7.4 #40

Closed bergsmat closed 4 years ago

bergsmat commented 4 years ago

Per Klaas (buglist), consder:

get.shrinkage = function (run, path = getOption("nmDir"), file.ext = ".lst",
                          text=list(eta = "ETASHRINK",ebv="EBVSHRINK",eps="EPSSHRINK")) 
{
  out = read.out(path = path, run = run, file.ext = file.ext)
  version = get.nm.version(path = path, run = run, file.ext = file.ext)
  txtETAStart = grep(text$eta, out)
  txtEBVStart = grep(text$ebv, out)
  txtEPSStart = grep(text$eps, out)
  txtETAParse = as.list(seq(length(txtETAStart)))
  txtEPSParse = txtEBVParse = txtETAParse
  for (i in 1:length(txtETAStart)) {
    txtETAParse[[i]] = txtETAStart[i]:(txtEBVStart[i] - 1)
    txtEBVParse[[i]] = txtEBVStart[i]:(txtEPSStart[i] - 1)
    txtEPSParse[[i]] = txtEPSStart[i]
  }
  etaShrink = lapply(txtETAParse, function(x, out) trimSpace(substring(paste(out[x], 
                                                                             collapse = ""), 16)), out = out)
  ebvShrink = lapply(txtEBVParse, function(x, out) trimSpace(substring(paste(out[x], 
                                                                             collapse = ""), 16)), out = out)
  epsShrink = lapply(txtEPSParse, function(x, out) trimSpace(substring(paste(out[x], 
                                                                             collapse = ""), 16)), out = out)
  nameParse = as.list(seq(length(etaShrink)))
  txtOBJParse = grep("FINAL PARAMETER ESTIMATE", out)
  for (i in 1:length(nameParse)) {
    nameParse[[i]] = trimSpace(sub("[*]+", "", sub("[*]+", 
                                                   "", out[txtOBJParse[i] - 1])))
  }
  names(etaShrink) = nameParse
  names(ebvShrink) = nameParse
  names(epsShrink) = nameParse
  return(list(version = version, eta = etaShrink, ebv = ebvShrink, 
              eps = epsShrink))
}
bergsmat commented 4 years ago

I had a hard time finding a single solution that works with both old and new versions of the list file. Consider using nonmemica to pull this info directly from the xml with a simple query. Here, I have simply retrograded the new list file version by knocking out the ...SHRINKVR records and converting SHRINKSD to 'shrink' (then process as normal).