Parametric Simulator

What would you like Pmetrics to do in the future?
Post Reply
User avatar
Andras Farkas
Posts: 53
Joined: Thu Nov 17, 2011 9:15 am
Location: Teaneck, NJ
Contact:

Parametric Simulator

Post by Andras Farkas » Tue May 08, 2012 9:43 am

Michael,

thanks for the answers on the other topics... While there is a parametric simulator avaible currently in the package to my understanding, the use of that simulator without an original dataset is not possible (please correct me if I am wrong). Most clinicians probably do not have original datasets availble to them and would need to do what is often done presently, which is to use a software that is capable of accepting measures of central tendencies and respective standard deviations extracted from the literature and use assumed distributions to simulate profiles without an original dataset. While probably it is not a function you would want in a package that is based on a method that detects actual distribution :( , I do believe that the lack of this function may have others choose to learn a different software instead. A function that would allow for a few different distributions (normal, lognormal, weibull with percentiles, uniform, triangular, and discrete distribution I have found very usefull for abx simulations during my carrier) and options for inclusion of covariates in the model, and the possibility of truncation would be great to have, I know I would use it exclusively once I learn it :) . Just some thoughts...

Andras

User avatar
mneely
Site Admin
Posts: 235
Joined: Tue Nov 08, 2011 11:08 am
Contact:

Re: Parametric Simulator

Post by mneely » Tue May 08, 2012 1:47 pm

Hi Andras,

The simulator in Pmetrics is quite versatile and already does most of what you ask. While it is true that it only works with normal distributions, any complex normal distribution can be specified. For each parameter, one can choose a single distribution, or any number of distributions with differing weights. I have used the method you describe - taking central tendencies and dispersions from the literature - many times.

To run the simulator, one needs to provide a prior distribution and a template. The prior distribution can be automatically extracted from a PMfinal object (loaded with NPload() or ITload() after a successful run), or it can be manually entered.

This manual entry is a list with 3 objects: weights, means, and covariance matrix. So for a model with unimodal Kel and Vd, you could enter:

weights <- 1
means <- c(0.1,50)
covar <- matrix(c(0.01,0,0,25))

SIMrun(poppar=list(weights,means,cover),...)

The objects in the popper list do not have to be named anything special, but they do have to be in that order: weight, mean, cover.

For a distribution bimodal in Kel, it would look like this, for example:

weights <- c(0.2,0.8)
means <- matrix(c(0.1,50,0.5,50))
covar <- matrix(c(0.01,0,0,25))

Note that there are two multivariate distributions now with means Kel=0.1,Vd=50 and Kel=0.5,Vd=50 and weights of 0.2 and 0.8 respectively. The overall covariance matrix will be divided by the number of distributions and applied to each distribution for sampling.

You can also already specify limits, which should be a matrix with the number of rows equal to the number of random parameters and 2 columns for the min and max, respectively. The simulator will track sets which are discarded for being outside the truncation limits and include them in a summary to verify that the requested distribution was achieved, even though the truncated distribution (also returned by the simulator) will be different than that requested by the user.

Finally, you can include any covariates that you wish in your template dosing/observation time file, although you cannot easily simulate them because you probably don't know the covariance with parameters.

I can see that I need to make a video tutorial on the simulator, as it is complex in its power! :D In the meantime, for help running it, look at "?SIMrun", i.e. help("SIMrun") in the R console.

User avatar
Andras Farkas
Posts: 53
Joined: Thu Nov 17, 2011 9:15 am
Location: Teaneck, NJ
Contact:

Re: Parametric Simulator

Post by Andras Farkas » Fri May 11, 2012 3:06 am

Hi Michael,

yes, tutorial for the Simulator sounds like a great idea :) ... The already availble 2 tutorials look great by the way... In the mean time though I am trying to figure it out, and here is what I ran into:

I placed model1.for and temp1.csv with 1 patients data in C:\\Pmetrics\\Runs directory. My Rscript looks like this (copy and paste your example from help):

library(Pmetrics)
setwd("C:\\Pmetrics\\Runs")
weights <- 1
mean <- log(c(0.7,0.05,100))
cov <- matrix(rep(0,length(mean)**2),ncol=length(mean))
diag(cov) <- (c(0.15,0.15,0.15)*mean)**2
poppar <- list(weights,mean,cov)
SIMrun(poppar,"temp1.csv",nsim=15,model="model1.for",obsNoise=c(0.02,0.1,0,0),makecsv="PMex1.csv",outname="example",cleanUp=T)

then I loaded Pmetrics_0.20, and got the error message:

Error in inherits(data, "PMmatrix") : argument "data" is missing, with no default

Then I did nothing other then loaded Pmetrics_0.19 instead of 0.20, the Rscript and all files remained the same and got the following message:

C:/Users/andras/Documents/R/win-library/2.15/Pmetrics/Sim/64/engine/SIMengGF_101E.o: file not recognized: File format not recognized
collect2: ld returned 1 exit status
'montbig.exe' is not recognized as an internal or external command, operable program or batch file.
Warning messages:
1: running command 'C:\Windows\system32\cmd.exe /c gfortran -m64 -O3 -o montbig.exe "C:/Users/andras/Documents/R/win-library/2.15/Pmetrics/Sim/64/engine/SIMengGF_101E.o" model1.for' had status 1
2: In shell(paste(enginecompile, model)) :'gfortran -m64 -O3 -o montbig.exe "C:/Users/andras/Documents/R/win-library/2.15/Pmetrics/Sim/64/engine/SIMengGF_101E.o" model1.for' execution failed with error code 1
3: running command 'C:\Windows\system32\cmd.exe /c montbig.exe DOS < simControl.txt' had status 1
4: In shell("montbig.exe DOS < simControl.txt") :'montbig.exe DOS < simControl.txt' execution failed with error code 1

in the second scenario the software actually seemed like started to begin the process, but then it stopped (v 0_.19), while in the first scenario (0_.20) it seems to not even move. Is my script completely off? Perhaps some of my files are not in the proper location? Apreciate the help,

Andras

User avatar
mneely
Site Admin
Posts: 235
Joined: Tue Nov 08, 2011 11:08 am
Contact:

Re: Parametric Simulator

Post by mneely » Fri May 11, 2012 12:58 pm

Ooops, sorry, I should have specified the data argument explicitly:

SIMrun(poppar,data="temp1.csv",nsim=15,model="model1.for",obsNoise=c(0.02,0.1,0,0),makecsv="PMex1.csv",outname="example",cleanUp=T)

I think (hope) that will take care of the problem.

User avatar
Andras Farkas
Posts: 53
Joined: Thu Nov 17, 2011 9:15 am
Location: Teaneck, NJ
Contact:

Re: Parametric Simulator

Post by Andras Farkas » Sat May 12, 2012 2:50 am

Michael,

one step closer, thank you. I tried the exact same settings and It begun to run but then got the following message:

The first subject in the data will serve as the template for simulation.

Simulating from subject 1 ...
At line 3202 of file .\Simulator\engine\MONT102.for (unit = 5, file = 'stdin')
Fortran runtime error: End of file

Use, for example, SIMparse(“example1.txt”) to extract simulator output for analysis or plotting.
Warning messages:
1: running command 'C:\Windows\system32\cmd.exe /c montbig.exe DOS < simControl.txt' had status 2
2: In shell("montbig.exe DOS < simControl.txt", invisible = T) :
'montbig.exe DOS < simControl.txt' execution failed with error code 2

In your example in the help you specified the following command which I am not using currently, what does this command refer to?:
setwd(paste(normalizePath(Sys.getenv("PmetricsPath"),winslash="/"),"/Pmetrics/example/Sim",sep=""))

I tried SIMparse, but example1.txt cannot be found. What do you think?

thank you,

have a great weekend

Andras

User avatar
mneely
Site Admin
Posts: 235
Joined: Tue Nov 08, 2011 11:08 am
Contact:

Re: Parametric Simulator

Post by mneely » Sat May 12, 2012 5:54 am

Hi Andras,

I think that there is a subtle bug in the new simulator, which was updated to handle steady state dosing for oral/bolus doses in the template file. I've run into the same problem myself, which I of course discovered after releasing 0.20. The new simulator passed my benchmark tests, but apparently is flaky.

I have found that it will work fine if you omit the "makecsv" argument and do not make one.

Mike van Guilder and I are working to identify and fix this problem.

The complex setwd command in the example is solely to ensure compatibility with Mac and Windows systems, and to navigate Pmetrics to the directory where some sample data can be found.

Post Reply