This is a five-minute quickstart tutorial for Maspectra™ masmod – the modeling and simulation framework in Python.

Import the mas.model package#

All the necessary functions and components for constructing a model are available within the mas.model package. Therefore, we can begin by importing them to facilitate the model construction process.

from mas.model import *

Write a model#

Here is a simple example of Emax model:

class EmaxModel(Module):
    def __init__(self) -> None:
        # definitions of the parameters
        self.tv_emax = theta(150)
        self.tv_ec50 = theta(40)
        self.tv_baseline = theta(20)

        self.eta_emax = omega(0.5)
        self.eta_ec50 = omega(0.5)
        self.eta_baseline = omega(0.5)

        self.eps_add = sigma(3)

        # declare the data columns required for the model
        self.cc = column('CC')

    def pred(self) -> Expression:
        emax = self.tv_emax * exp(self.eta_emax)
        ec50 = self.tv_ec50 * exp(self.eta_ec50)
        baseline = self.tv_baseline * exp(self.eta_baseline)

        ipred = (self.cc * emax) / (self.cc + ec50) + baseline

        y = ipred + self.eps_add

        return y

To estimate or simulate from a Population Model, we declare so via the PopModel class (see example below), which compiles and validates the ModelData (if provided) is compatible with the defined model. If the model has been compiled before and no changes have been made, the compiling step is skipped.

emax_model_simu = PopModel(EmaxModel)
🔧 CXX compiler /opt/homebrew/bin/g++
📦 Compiling build target...
🔗 Linking dynamic library...
✅ Compilation Finished

To learn more about PopModel, please refer to the Build and fit models section. For further information on ModelData, please consult the Create data for models section.

Model estimation and simulation#

An example is presented in ref{case-warfarin}.