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.00051529 0.00055262 0.00179893]
The simulated covariances are:
print(np.cov(data.T))
[[0.00991758 0.00117877 0.02221338]
[0.00117877 0.00247654 0.00608111]
[0.02221338 0.00608111 0.06163174]]
The simulated correlation coefficients are:
print(np.corrcoef(data.T))
[[1. 0.23784914 0.89848237]
[0.23784914 1. 0.49221792]
[0.89848237 0.49221792 1. ]]