simPopInternal {SUMMER} | R Documentation |
Internal functions for population simulation
Description
Functions for calculating valuable quantities and for drawing from important distributions for population simulation.
Usage
getExpectedNperEA(easpa, popMat, level = c("grid", "EA"), pixelIndexMat = NULL)
getSortIndices(
i,
urban = TRUE,
popMat,
stratifyByUrban = TRUE,
validationPixelI = NULL
)
rStratifiedMultnomial(n, popMat, easpa, stratifyByUrban = TRUE)
rStratifiedMultnomialBySubarea(
n,
popMat,
easpa,
stratifyByUrban = TRUE,
poppsub = NULL,
min1PerSubarea = TRUE,
minSample = 1
)
rMyMultinomial(
n,
i,
stratifyByUrban = TRUE,
urban = TRUE,
popMat = NULL,
easpa = NULL,
min1PerSubarea = FALSE,
method = c("mult1", "mult", "indepMH"),
minSample = 1
)
rMyMultinomialSubarea(
n,
i,
easpsub,
stratifyByUrban = TRUE,
urban = TRUE,
popMat = NULL
)
rmultinom1(
n = 1,
size,
prob,
maxSize = 8000 * 8000,
method = c("mult1", "mult", "indepMH"),
verbose = FALSE,
minSample = 100,
maxExpectedSizeBeforeSwitch = 1000 * 1e+07,
init = NULL,
burnIn = floor(n/4),
filterEvery = 10,
zeroProbZeroSamples = TRUE,
allowSizeLessThanK = FALSE
)
sampleNMultilevelMultinomial(
nDraws = ncol(pixelIndexMat),
pixelIndexMat = NULL,
urbanMat = NULL,
areaMat = NULL,
easpaList,
popMat,
stratifyByUrban = TRUE,
verbose = TRUE,
returnEAinfo = FALSE,
minHHPerEA = 25,
fixHHPerEA = NULL,
fixPopPerHH = NULL
)
sampleNMultilevelMultinomialFixed(
clustersPerPixel,
nDraws = ncol(pixelIndices),
pixelIndices = NULL,
urbanVals = NULL,
areaVals = NULL,
easpa,
popMat,
stratifyByUrban = TRUE,
verbose = TRUE
)
Arguments
easpa |
Census frame. See |
popMat |
data.frame of pixellated grid of population densities. See |
level |
Whether to calculate results at the integration grid or EA level |
pixelIndexMat |
Matrix of pixel indices associated with each EA and draw. Not required by getExpectedNperEA unless level == "EA" |
i |
Index |
urban |
If TRUE, calculate only for urban part of the area. If FALSE, for only rural part |
stratifyByUrban |
whether or not to stratify calculations by urban/rural classification |
validationPixelI |
CURRENTLY FOR TESTING PURPOSES ONLY a set of indices of pixels for which we want to simulate populations (used for pixel level validation) |
n |
Number of samples |
poppsub |
Population per subarea. See |
min1PerSubarea |
Whether or not to ensure there is at least 1 EA per subarea. See |
minSample |
The minimum number of samples per 'chunk' of samples for truncated multinomial sampling. Defaults to 1 |
method |
If min1PerSubarea is TRUE, the sampling method for the truncated multinomial to use with rmulitnom1. rmultinom1 automatically switches between them depending on the number of expected samples. The methods are:
|
easpsub |
This could either be total EAs per subarea, or subarea crossed with urban or rural if stratifyByUrban is TRUE |
size |
Multinomial size parameter. See |
prob |
Multinomial probability vector parameter. See |
maxSize |
The maximum number of elements in a matrix drawn from the proposal distribution per sample chunk. |
verbose |
Whether to print progress as the function proceeds |
maxExpectedSizeBeforeSwitch |
Max expected number of samples / k, the number of categories, before switching method |
init |
Initial sample if method is 'indepMH' |
burnIn |
Number of initial samples before samples are collected if method is 'indepMH' |
filterEvery |
Store only every filterEvery samples if method is i'indepMH' |
zeroProbZeroSamples |
If TRUE, set samples for parts of prob vector that are zero to zero. Otherwise they are set to one. |
allowSizeLessThanK |
If TRUE, then if size < the number of categories (k), returns matrix where each column is vector of size ones and k - size zeros. If FALSE, throws an error if size < k |
nDraws |
Number of draws |
urbanMat |
Matrix of urbanicities associated with each EA and draw |
areaMat |
Matrix of areas associated with each EA and draw |
easpaList |
A list of length n with each element being of the format of easpa giving the number of households and EAs per stratum. It is assumed that the number of EAs per stratum is the same in each list element. If easpaList is a data frame, number of households per stratum is assumed constant |
returnEAinfo |
Whether a data frame at the EA level is desired |
minHHPerEA |
The minimum number of households per EA (defaults to 25, since that is the number of households sampled per DHS cluster) |
fixHHPerEA |
If not NULL, the fixed number of households per EA |
fixPopPerHH |
If not NULL, the fixed target population per household |
clustersPerPixel |
CURRENTLY FOR TESTING PURPOSES ONLY a vector of length nIntegrationPoints specifying the number of clusters per pixel if they are fixed |
pixelIndices |
A nEA x n matrix of pixel indices associated with each EA per simulation/draw |
urbanVals |
A nEA x n matrix of urbanicities associated with each EA per simulation/draw |
areaVals |
A nEA x n matrix of area names associated with each EA per simulation/draw |
Functions
-
getExpectedNperEA()
: Calculates expected denominator per enumeration area. -
getSortIndices()
: For recombining separate multinomials into the draws over all grid points -
rStratifiedMultnomial()
: Gives nIntegrationPoints x n matrix of draws from the stratified multinomial with values corresponding to the value of |C^g| for each pixel, g (the number of EAs/pixel) -
rStratifiedMultnomialBySubarea()
: Gives nIntegrationPoints x n matrix of draws from the stratified multinomial with values -
rMyMultinomial()
: -
rMyMultinomialSubarea()
: -
rmultinom1()
: Random (truncated) multinomial draws conditional on the number of each type being at least one -
sampleNMultilevelMultinomial()
: Take multilevel multinomial draws first from joint distribution of number of households per EA given the total per stratum, and then from the joint distribution of the total target population per household given the total per stratum -
sampleNMultilevelMultinomialFixed()
: Same as sampleNMultilevelMultinomial, except the number of EAs per pixel is fixed