pharmpy.math module¶
- pharmpy.math.conditional_joint_normal(mu, sigma, a)[source]¶
Give parameters of the conditional joint normal distribution
The condition is the last len(a) values
See https://en.wikipedia.org/wiki/Multivariate_normal_distribution#Conditional_distributions
- pharmpy.math.corr2cov(corr, sd)[source]¶
Convert correlation matrix to covariance matrix
- Parameters
corr – Correlation matrix (ones on diagonal)
sd – One dimensional array of standard deviations
- pharmpy.math.flattened_to_symmetric(x)[source]¶
Convert a vector containing the elements of a lower triangular matrix into a full symmetric matrix
- pharmpy.math.nearest_posdef(A)[source]¶
Return the nearest positive definite matrix in the Frobenius norm to a matrix
A Python/Numpy port of John D’Errico’s nearestSPD MATLAB code [1], which credits [2]. [1] https://www.mathworks.com/matlabcentral/fileexchange/42885-nearestspd [2] N.J. Higham, “Computing a nearest symmetric positive semidefinite matrix” (1988): https://doi.org/10.1016/0024-3795(88)90223-6 [3] https://gist.github.com/fasiha/fdb5cec2054e6f1c6ae35476045a0bbd
- pharmpy.math.round_and_keep_sum(x, s)[source]¶
Round values in Series x and their sum must be s
- Algorithm: Floor all elements in series. If sum not correct add one to element with
highest fractional part until sum is reached.
- pharmpy.math.sample_truncated_joint_normal(mu, sigma, a, b, n, seed=None)[source]¶
Give an array of samples from the truncated joint normal distributon using sample rejection - mu, sigma - parameters for the normal distribution - a, b - vectors of lower and upper limits for each random variable - n - number of samples
- pharmpy.math.se_delta_method(expr, values, cov)[source]¶
Use the delta method to estimate the standard error of a function of parameters with covariance matrix available.
- Parameters
expr – A sympy expression for the function of parameters
cov – Dataframe with symbol names as indices must include at least all parameters needed for expr
values – dict/series parameter estimates. Must include at least all parameters needed for expr
- Returns
Approximation of the standard error