Pmetrics icon indicating copy to clipboard operation
Pmetrics copied to clipboard

SIMrun will not create csv if all but one covariates are fixed

Open mhovd opened this issue 4 years ago • 1 comments

During some testing with SIMrun, I encountered an error. When the number of non-fixed covariates to be simulated is one, SIMrun will fail to create a csv-file with the data. This is the error: Error in (nfixed + 1):(nfixed + ncol(covDF)) : argument of length 0.

I believe this error is because ncol(covDF) evaluates to NULL.

Here is a minimal example reproducing the error:

library(Pmetrics)

PMwriteMatrix(data = mdata.1, filename = "template.csv")
writeLines(model, con = "model.txt")

SIMrun(makecsv = "simdata.csv", include = 1, model = "model.txt", 
       data = "template.csv", poppar = final.1, nsim = 10,
       covariate = list(cov = cov.1, fix = c("africa","age","gender","height")))

Setting obsNoise to model file assay error. When making a csv file, you cannot specify no obsNoise.

Model solver mode: Algebraic Number of compartments: 2, including an absorptive compartment Primary Variables: Ka, Ke, V, Tlag1, wt Covariates in data file: africa, age, gender, height Covariates used in model file: africa, age, gender, height Secondary Variables: KCP, KPC Model conditions: no bioavailability term defined, initial conditions are zero, lag term defined

The following subject(s) in the data will serve as the template(s) for simulation: 1

Simulating from subject 1 ... Error in (nfixed + 1):(nfixed + ncol(covDF)) : argument of length 0

mhovd avatar Dec 03 '21 10:12 mhovd

This issue still appears to be present in 2.0, with the following example


NPex$sim(
  nsim = 1,
  include = 1,
  covariate = list(
    cov = NPex$cov,
    fix = c("africa", "age", "gender", "height")
  ), makecsv = "out.csv"
)

Error in (nfixed + 1):(nfixed + ncol(covDF)) : argument of length 0
In addition: Warning message:
In cbind(covDF, temp[, nfixed + covNotSimPos]) :
  number of rows of result is not a multiple of vector length (arg 2)

mhovd avatar Feb 04 '24 15:02 mhovd

This is no longer an issue when using the Rust-based simulator.

mhovd avatar Jan 17 '25 06:01 mhovd