Description Usage Arguments Details Value See Also Examples
weights
should have one or more dimensions that counts
does
not. The contents of each cell in counts
are randomly distributed
across these extra dimensions.
1 2 3 4 5 6 7 8 9 10 | redistribute(counts, weights, means = FALSE, n = NULL)
## S4 method for signature 'Counts,DemographicArray'
redistribute(counts, weights, means = FALSE, n = NULL)
## S4 method for signature 'Values,DemographicArray'
redistribute(counts, weights, n = NULL)
## S4 method for signature 'numeric,DemographicArray'
redistribute(counts, weights, means = FALSE, n = NULL)
|
counts |
Object of class |
weights |
Object of class |
means |
If |
n |
Number of iterations to generate. Ignored if |
Each cell in counts
is redistributed by drawing from a multinomial
distribution with size equal to the value of the cell and probabiltiies
proportional to the values of the corresponding cells in weights
.
weights
is typically a set of observed counts, such a
cross-tabulation of records with no missing data. However, weights
could also be a sample from a posterior distribution.
An Counts
object with the same dimensions and
metadata as weights
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | x <- Counts(array(c(10, 12),
dim = 2,
dimnames = list(sex = c("Female", "Male"))))
y <- Counts(array(0:5,
dim = c(2, 3),
dimnames = list(sex = c("Female", "Male"),
region = c("A", "B", "C"))))
redistribute(x, weights = y)
## specify the number of iterations
redistribute(x, weights = y, n = 3)
ans <- redistribute(x, weights = y)
ans
## reverse the effects
collapseDimension(ans, dimension = "region")
## give all cells a chance of being non-zero
redistribute(x, weights = y + 0.1, n = 10)
## 'counts' is a single value
redistribute(10, weights = y)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.