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) POP_CL POP_VC COVAPGR IIV_CL IIV_VC SIGMA 0 0.004887 1.000761 0.198184 0.034860 0.031391 0.013750 1 0.004631 1.024746 0.071056 0.031726 0.026824 0.012597 2 0.004631 0.991088 0.130841 0.027464 0.024589 0.013215
See also
sample_parameters_uniformly
Sample parameter vectors using uniform distribution
sample_individual_estimates
Sample individual estiates given their covariance