4. Algorithms
4.1. Fit
4.1.1. Prerequisites
Data format and preprocessing steps.
4.1.2. Running Task
How to run the fit algorithm.
Example commands and code snippets.
4.1.3. Output
What results to expect from the fitting process.
DataFrame object
Plotting object
4.1.4. Setting Options (Different Models)
How to set specific options for different types of models.
Customizing parameters for logistic, joint, mixture, and covariate models.
4.2. Personalize
The idea of this section is to describe how the inference over new patients could be done. For this, random effects of new patients should be estimated using some follow-up visits to be able to describe their progression and make predictions about their future progression. We assume that fixed effects have already been estimated. To estimate the random effects, two main approaches exist in Leaspy.
more of a frequentist one: random effects are estimated using the solver minimise from the package Scipy [15] to maximize the likelihood knowing the fixed effects.
>>> personalize_settings = AlgorithmSettings("scipy_minimize", seed=0)
>>> algorithm = algorithm_factory(personalize_settings)
>>> individual_parameters = algorithm.run(model, dataset)
==> Setting seed to 0
|##################################################| 200/200 subjects
Personalize with `AlgorithmName.PERSONALIZE_SCIPY_MINIMIZE` took: 29s
The standard-deviation of the noise at the end of the AlgorithmType.PERSONALIZE is: 6.85%
>>> individual_parameters.to_dataframe()
sources_0 sources_1 tau xi
ID
GS-001 0.027233 -0.423354 76.399582 -0.386364
GS-002 -0.262680 0.665351 75.137474 -0.577525
GS-003 0.409585 0.844824 75.840012 0.102436
GS-004 0.195366 0.056577 78.110085 0.433171
GS-005 1.424637 1.054663 84.183098 -0.051317
... ... ... ... ...
GS-196 0.961941 0.389468 72.528786 0.354126
GS-197 -0.561685 -0.720041 79.006042 -0.624100
GS-198 -0.061995 0.177671 83.596138 0.201686
GS-199 1.932454 1.820023 92.275978 -0.136224
GS-200 1.152407 -0.171888 76.504517 0.770118
[200 rows x 4 columns]
more a bayesian one: random effects are estimated using a Gibbs sampler with an option on the burn-in phase (see fit description)and temperature scheme fit description. Currently, the package enables to extract the mean or the mode of the posterior distribution. They can be used with the same procedure using mean_posterior or mode_posterior flag.
>>> personalize_settings = AlgorithmSettings("mean_posterior", seed=0)
>>> algorithm = algorithm_factory(personalize_settings)
>>> individual_parameters = algorithm.run(model, dataset)
==> Setting seed to 0
|##################################################| 1000/1000 iterations
Personalize with `mean_posterior` took: 1s
>>> individual_parameters.to_dataframe()
sources_0 sources_1 tau xi
ID
GS-001 0.027233 -0.423354 76.399582 -0.386364
GS-002 -0.262680 0.665351 75.137474 -0.577525
GS-003 0.409585 0.844824 75.840012 0.102436
GS-004 0.195366 0.056577 78.110085 0.433171
GS-005 1.424637 1.054663 84.183098 -0.051317
... ... ... ... ...
GS-196 0.961941 0.389468 72.528786 0.354126
GS-197 -0.561685 -0.720041 79.006042 -0.624100
GS-198 -0.061995 0.177671 83.596138 0.201686
GS-199 1.932454 1.820023 92.275978 -0.136224
GS-200 1.152407 -0.171888 76.504517 0.770118
[200 rows x 4 columns]
4.3. Estimate
4.4. Simulate
4.5. Data Generalities
monotonicity
NaN
number of visits
outliers
not enough patients
parameters don’t converge
score don’t progress
4.6. References
Pauli Virtanen, Ralf Gommers, Travis E. Oliphant, Matt Haberland, Tyler Reddy, David Cournapeau, Evgeni Burovski, Pearu Peterson, Warren Weckesser, Jonathan Bright, Stéfan J. van der Walt, Matthew Brett, Joshua Wilson, K. Jarrod Millman, Nikolay Mayorov, Andrew R. J. Nelson, Eric Jones, Robert Kern, Eric Larson, C J Carey, İlhan Polat, Yu Feng, Eric W. Moore, Jake VanderPlas, Denis Laxalde, Josef Perktold, Robert Cimrman, Ian Henriksen, E. A. Quintero, Charles R. Harris, Anne M. Archibald, Antônio H. Ribeiro, Fabian Pedregosa, Paul van Mulbregt, and SciPy 1.0 Contributors. SciPy 1.0: Fundamental Algorithms for Scientific Computing in Python. Nature Methods, 17:261–272, 2020. doi:10.1038/s41592-019-0686-2.