add_covariate_effect#

pharmpy.modeling.add_covariate_effect(model, parameter, covariate, effect, operation='*', allow_nested=False)[source]#

Adds covariate effect to pharmpy.model.

The following effects have templates:

  • Linear function for continuous covariates (lin)
    • Function:

    coveff=1+theta(covmedian)
    • Init: 0.001

    • Upper:
      • If median of covariate equals minimum: 100,000

      • Otherwise: 1medianmin

    • Lower:
      • If median of covariate equals maximum: -100,000

      • Otherwise: 1medianmax

  • Linear function for categorical covariates (cat)
    • Function:
      • If covariate is the most common category:

      coveff=1
      • For each additional category:

      coveff=1+theta
    • Init: 0.001

    • Upper: 5

    • Lower: -1

  • (alternative) Linear function for categorical covariates (cat2)
    • Function:
      • If covariate is the most common category:

      coveff=1
      • For each additional category:

      coveff=theta
    • Init: 0.001

    • Upper: 6

    • Lower: 0

  • Piecewise linear function/”hockey-stick”, continuous covariates only (piece_lin)
    • Function:
      • If cov <= median:

      coveff=1+theta1(covmedian)
      • If cov > median:

      coveff=1+theta2(covmedian)
    • Init: 0.001

    • Upper:
      • For first state: 1medianmin

      • Otherwise: 100,000

    • Lower:
      • For first state: -100,000

      • Otherwise: 1medianmax

  • Exponential function, continuous covariates only (exp)
    • Function:

    coveff=exp(theta(covmedian))
    • Init:
      • If lower > 0.001 or upper < 0.001: upperlower2

      • If estimated init is 0: upper2

      • Otherwise: 0.001

    • Upper:
      • If min - median = 0 or max - median = 0: 100

      • Otherwise:

      min(log(0.01)minmedian,log(100)maxmedian)
    • Lower:
      • If min - median = 0 or max - median = 0: 0.01

      • Otherwise:

      max(log(0.01)maxmedian,log(100)minmedian)
  • Power function, continuous covariates only (pow)
    • Function:

    coveff=(covmedian)theta
    • Init: 0.001

    • Upper: 100,000

    • Lower: -100

Parameters:
  • model (Model) – Pharmpy model to add covariate effect to.

  • parameter (str) – Name of parameter to add covariate effect to.

  • covariate (str) – Name of covariate.

  • effect (str) – Type of covariate effect. May be abbreviated covariate effect (see above) or custom.

  • operation (str, optional) – Whether the covariate effect should be added or multiplied (default).

  • allow_nested (bool, optional) – Whether to allow adding a covariate effect when one already exists for the input parameter-covariate pair.

Returns:

Model – Pharmpy model object

Examples

>>> from pharmpy.modeling import *
>>> model = load_example_model("pheno")
>>> model = add_covariate_effect(model, "CL", "APGR", "exp")
>>> model.statements.before_odes.full_expression("CL")
POP_CL*WGT*exp(ETA_CL + POP_CLAPGR*(APGR - 7.0))