Simulation#

The simulation tool is a tool for running simulations.

Running#

The simulation tool is available both in Pharmpy and pharmr.

To initiate the simulation tool in Python/R:

from pharmpy.tools import run_simulation

model = read_model('path/to/model')
res = run_simulation(model)

In order to run a simulation for a model the model needs to have DV in the output table and a simulation step. A simulation step can be added using set_simulation(model, n=N) with N being the number of simulations.

Arguments#

The input argument to the simulation tool is a model object containing a simulation step.

Argument

Description

model

Model

Examples#

Example of adding a simulation step to a model and running the simulation tool:

from pharmpy.modeling import set_simulation
from pharmpy.tools import run_simulation

model = read_model('path/to/model')
model = set_simulation(model, n=300)
res = run_simulation(model)

The Simulation results#

The results of the simulation will be stored in the results.csv file. The simulation table contains the simulation number, index and DV value:

from pharmpy.tools import run_simulation

model = read_model('path/to/model')
res = run_simulation(model)
res.table
DV
SIM index
1 0 0.000
1 24.343
2 0.000
3 0.000
4 0.000
... ... ...
10 739 0.000
740 0.000
741 0.000
742 0.000
743 38.076

7440 rows × 1 columns