Introduction#

The following vignettes describe how to set up models where the details of genetic value/fitness calculations differ between demes.

Different effect sizes in different demes.#

The next several vignettes describe how to set up scenarios where the effect size of a mutation differs between demes. Briefly, simulating such models entails:

  • Using fwdpy11.mvDES to define a multivariate distribution of effect sizes.

  • Passing new parameters to our genetic value types to indicate how many demes to expect during the simulation.

Correlation and covariance matrices#

The next sections describe types that require covariance matrices as inputs. Many people may find it easier to think about correlations between variables than covariances.

This section shows how to start with a correlation matrix and convert it to a covariance matrix.

Starting with a 3x3 correlation matrix:

import numpy as np
corr = np.matrix([1,0.25,0.9,0.25,1,0.5,0.9,0.5,1]).reshape(3,3)
print(corr)
[[1.   0.25 0.9 ]
 [0.25 1.   0.5 ]
 [0.9  0.5  1.  ]]

We wish to convert this to a covariance matrix with the following standard deviations:

sd = np.array([0.1, 0.05, 0.25])

The procedure is:

D = np.identity(3)
np.fill_diagonal(D, sd)
cov = np.matmul(np.matmul(D, corr), D)

The covariance matrix is:

print(cov)
[[0.01    0.00125 0.0225 ]
 [0.00125 0.0025  0.00625]
 [0.0225  0.00625 0.0625 ]]

Let’s simulate a bunch of multivariate normal data from this matrix. We will sample from a distribution with means of 0.

data = np.random.multivariate_normal([0, 0, 0], cov, size=10000)

The simulated means are:

print(data.mean(axis=0))
[-0.00045167 -0.00094191 -0.00128238]

The simulated covariances are:

print(np.cov(data.T))
[[0.00998427 0.00117829 0.02234472]
 [0.00117829 0.0024285  0.00599023]
 [0.02234472 0.00599023 0.06174992]]

The simulated correlation coefficients are:

print(np.corrcoef(data.T))
[[1.         0.23928928 0.89990876]
 [0.23928928 1.         0.48916633]
 [0.89990876 0.48916633 1.        ]]