DFE parametrizations

DFE parametrizations#

The DFE needs to be parametrized in some way in order to be amenable to maximum likelihood estimation. GammaExpParametrization is used by default. Other parametrizations are also implemented (cf. parametrization). You can also create your own parametrization by subclassing Parametrization.

To see how the parametrization affects the shape of the DFE, we use our example data for B. pendula.

import fastdfe as fd
import logging

# set logging level to only show very important messages
logging.getLogger('fastdfe').setLevel(logging.FATAL)

# the different DFE parametrizations
parametrizations = [
    fd.GammaExpParametrization(),
    fd.DiscreteParametrization(),
    fd.GammaDiscreteParametrization(),
    fd.DisplacedGammaParametrization()
]

inferences = []
for p in parametrizations:
    # create inference object
    inference = fd.BaseInference(
        sfs_neut=fd.Spectrum([177130, 997, 441, 228, 156, 117, 114, 83, 105, 109, 652]),
        sfs_sel=fd.Spectrum([797939, 1329, 499, 265, 162, 104, 117, 90, 94, 119, 794]),
        model=p,
        do_bootstrap=True
    )

    # run inference
    inference.run()

    inferences.append(inference)

# plot the inferred DFEs
fd.Inference.plot_discretized(
    inferences=inferences,
    labels=[p.__class__.__name__ for p in parametrizations]
);
Discretization>Precomputing: 100%|██████████| 9/9 [00:00<00:00, 48.60it/s]
BaseInference>Performing inference: 100%|██████████| 10/10 [00:00<00:00, 16.84it/s]
BaseInference>Bootstrapping: 100%|██████████| 100/100 [00:01<00:00, 59.85it/s]
Discretization>Precomputing: 100%|██████████| 9/9 [00:00<00:00, 27.06it/s]
BaseInference>Performing inference: 100%|██████████| 10/10 [00:00<00:00, 17.51it/s]
BaseInference>Bootstrapping: 100%|██████████| 100/100 [00:02<00:00, 38.58it/s]
Discretization>Precomputing: 100%|██████████| 9/9 [00:00<00:00, 26.41it/s]
BaseInference>Performing inference: 100%|██████████| 10/10 [00:00<00:00, 18.75it/s]
BaseInference>Bootstrapping: 100%|██████████| 100/100 [00:01<00:00, 74.38it/s] 
Discretization>Precomputing: 100%|██████████| 9/9 [00:00<00:00, 26.50it/s]
BaseInference>Performing inference: 100%|██████████| 10/10 [00:00<00:00, 12.25it/s]
BaseInference>Bootstrapping: 100%|██████████| 100/100 [00:01<00:00, 50.46it/s]
../../_images/ddb95e8727795cb434377c7fb6a2117d031d6cf2c7fa178622f74c2763f5e46f.png

The shape is rather similar overall, but DiscreteParametrization appears to have larger confidence intervals.