| redistribute {dembase} | R Documentation |
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.
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.
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)