sample_parameters_from_covariance_matrix#

pharmpy.modeling.sample_parameters_from_covariance_matrix(model, parameter_estimates, covariance_matrix, force_posdef_samples=None, force_posdef_covmatrix=False, n=1, seed=None)[source]#

Sample parameter vectors using the covariance matrix

If parameters is not provided all estimated parameters will be used

Parameters:
  • model (Model) – Input model

  • parameter_estimates (pd.Series) – Parameter estimates to use as means in sampling

  • covariance_matrix (pd.DataFrame) – Parameter uncertainty covariance matrix

  • force_posdef_samples (int) – Set to how many iterations to do before forcing all samples to be positive definite. None is default and means never and 0 means always

  • force_posdef_covmatrix (bool) – Set to True to force the input covariance matrix to be positive definite

  • n (int) – Number of samples

  • seed (Generator) – Random number generator

Returns:

pd.DataFrame – A dataframe with one sample per row

Example

>>> from pharmpy.modeling import *
>>> from pharmpy.tools import load_example_modelfit_results
>>> model = load_example_model("pheno")
>>> results = load_example_modelfit_results("pheno")
>>> rng = create_rng(23)
>>> cov = results.covariance_matrix
>>> pe = results.parameter_estimates
>>> sample_parameters_from_covariance_matrix(model, pe, cov, n=3, seed=rng)
      PTVCL      PTVV   THETA_3      IVCL       IVV  SIGMA_1_1
0  0.005069  0.974989  0.204629  0.024756  0.012088   0.012943
1  0.004690  0.958431  0.233231  0.038866  0.029000   0.012516
2  0.004902  0.950778  0.128388  0.019020  0.023866   0.013413

See also

sample_parameters_uniformly

Sample parameter vectors using uniform distribution

sample_individual_estimates

Sample individual estiates given their covariance