Description Usage Arguments Value
Given a function kern(r) that gives per-individual migration rates and a resolution, returns the (approximate) function giving per-individual migration rates *per unit area* from squares of side length 'resolution' centered at distance r. (This depends on the direction the cell is in, but the result averages over directions.)
1 2 | discretize_kernel(kern, res, radius, sigma = 1, fact = 10, sim = ((kern(1)
== exp(-1/2)/(2 * pi)) && (fact > 10)))
|
kern |
The migration rate function. |
res |
The resolution of the grid. |
radius |
The maximum distance to extrapolate out to. |
sigma |
Distance scaling for kernel. |
fact |
The number of divisions of each grid cell side when approximating the integral. |
sim |
Whether to obtain the result by Monte Carlo integration (currently only implemented for the Gaussian kernel). |
A function as output by 'approxfun()', determined by numerical integration. If the required number of grid cells in the approximation is too large, falls back on Monte Carlo integration.
The result is designed to be used in migration_matrix, which scales input to the kernel by sigma and assumes that the kernel is a density function, so multiplies the value by the area of a cell; so the resulting function scales as a density function, and takes input in units of sigma.
For good results, the 'fine' grid used in numerical integration should be smaller than sigma; since the fine grid has a scale of res/fact, you should set fact >= 3 * res / sigma, say.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.