RandomVariable#
- class pharmpy.model.RandomVariable(name, level, sympy_rv=None)[source]#
Bases:
object
A single random variable
- Parameters:
name (str) – Name of the random variable
level (str) – Name of the variability level. The default levels are IIV, IOV and RUV
sympy_rv (sympy.RandomSymbol) – RandomSymbol to use for this random variable. See also the normal and joint_normal classmethods.
Examples
>>> import sympy >>> import sympy.stats >>> from pharmpy.model import RandomVariable >>> name = "ETA(1)" >>> sd = sympy.sqrt(sympy.Symbol('OMEGA(1,1)')) >>> rv = RandomVariable(name, "IIV", sympy.stats.Normal(name, 0, sd)) >>> rv ETA(1) ~ N(0, OMEGA(1,1))
See also
Attributes Summary
Free symbols including random variable itself
Names of all (including this) jointly varying rvs in a list
Name of the random variable
List of names of all parameters used in definition
Corresponding sympy random variable
Methods Summary
copy
()Make copy of RandomVariable
joint_normal
(names, level, mu, sigma)Create joint normally distributed random variables
normal
(name, level, mean, variance)Create a normally distributed random variable
subs
(d)Substitute expressions
Attributes Documentation
- free_symbols#
Free symbols including random variable itself
- joint_names#
Names of all (including this) jointly varying rvs in a list
- level#
- name#
Name of the random variable
- parameter_names#
List of names of all parameters used in definition
- sympy_rv#
Corresponding sympy random variable
Methods Documentation
- classmethod joint_normal(names, level, mu, sigma)[source]#
Create joint normally distributed random variables
- Parameters:
names (list) – Names of the random variables
level (str) – Variability level
mu (matrix or list) – Vector of the means of the random variables
sigma (matrix or list of lists) – Covariance matrix of the random variables
Example
>>> from pharmpy.model import RandomVariable, Parameter >>> omega_cl = Parameter("OMEGA_CL", 0.1) >>> omega_v = Parameter("OMEGA_V", 0.1) >>> corr_cl_v = Parameter("OMEGA_CL_V", 0.01) >>> rv1, rv2 = RandomVariable.joint_normal(["IIV_CL", "IIV_V"], 'IIV', [0, 0], ... [[omega_cl.symbol, corr_cl_v.symbol], [corr_cl_v.symbol, omega_v.symbol]]) >>> rv1 ⎡IIV_CL⎤ ⎧⎡0⎤ ⎡ OMEGA_CL OMEGA_CL_V⎤⎫ ⎢ ⎥ ~ N⎪⎢ ⎥, ⎢ ⎥⎪ ⎣IIV_V ⎦ ⎩⎣0⎦ ⎣OMEGA_CL_V OMEGA_V ⎦⎭
- classmethod normal(name, level, mean, variance)[source]#
Create a normally distributed random variable
- Parameters:
name (str) – Name of the random variable
level (str) – Name of the variability level
mean (expression or number) – Mean of the random variable
variance (expression or number) – Variance of the random variable
Example
>>> from pharmpy.model import RandomVariable, Parameter >>> omega = Parameter('OMEGA_CL', 0.1) >>> rv = RandomVariable.normal("IIV_CL", "IIV", 0, omega.symbol) >>> rv IIV_CL ~ N(0, OMEGA_CL)
- subs(d)[source]#
Substitute expressions
- Parameters:
d (dict) – Dictionary of from: to pairs for substitution
Examples
>>> import sympy >>> from pharmpy.model import RandomVariable, Parameter >>> omega = Parameter("OMEGA_CL", 0.1) >>> rv = RandomVariable.normal("IIV_CL", "IIV", 0, omega.symbol) >>> rv.subs({omega.symbol: sympy.Symbol("OMEGA_NEW")}) >>> rv IIV_CL ~ N(0, OMEGA_NEW)