Using built-in utils¶
There are a number of functionalities available from MISCore that are frequently used in processes.
They are optimized for speed using Cython.
It is often more efficient to use these built-in utils in processes than to code a solution yourself.
More details on each of the classes can be found in the utils reference guide.
Piecewise linear function¶
A PiecewiseLinear function can for example be used to interpolate cure probabilities between ages.
>>> data = [
... (0, 1.00),
... (20, 1.00),
... (40, 0.90),
... (60, 0.75),
... (80, 0.52),
... (100, 0.30)
... ]
>>> cure_probability = miscore.utils.PiecewiseLinear(data)
>>> cure_probability(52)
0.81
>>> cure_probability.array([50, 51, 52, 53, 54, 55])
array([0.825 , 0.8175, 0.81 , 0.8025, 0.795 , 0.7875])
Piecewise constant function¶
Use a PiecewiseConstant function (or step function) if the output should be constant between ages.
>>> cure_probability = miscore.utils.PiecewiseConstant(data)
>>> cure_probability(52)
0.9
Categorical distribution¶
The CategoricalDist can for example be used to randomly select a treatment for diagnosed individuals.
>>> data = [(0.8, "treatment 1"), (0.2, "treatment 2")]
>>> treatment = miscore.utils.CategoricalDist(data)
>>> random_values = [0.1, 0.9, 0.5]
>>> [treatment(i) for i in random_values]
['treatment 1', 'treatment 2', 'treatment 1']
Weibull distribution¶
The WeibullDistribution can for example be used to model cancer dwell or survival times.
>>> wd = WeibullDistribution(mean=1, shape=2)
>>> wd.mean
1.0
>>> wd.variance
0.27323954473516254
Values can be drawn by specifying a (random) number in [0, 1].
>>> wd(0.784)
0.5566310084367094
Inverse generalised logistic function¶
The InverseGeneralisedLogisticFunction can for example be used to model increasing risk of lesion onset by age.
>>> func = miscore.utils.InverseGeneralisedLogisticFunction(k=20, q=100, b=0.05, v=0.15)
>>> func(np.array([0.1]))
array([88.22693142])
>>> func(np.array([0.1, 0.5, 0.9]))
array([ 88.22693142, 98.15153043, 102.57908246])