How a design splits its sample over the strata of a frame
Source:R/design-stratified.R
allocation_table.RdThe rows draw() takes from each stratum, the inclusion probability that
gives each row there, and the reason for any stratum held at the floor,
capped at its size or left with no rows, all before anything is drawn.
Under Neyman allocation it also shows the standard deviation of each
stratum the split used, and the cost per row when the design has costs.
The numbers come from the same computation as draw() and
inclusion_prob(), so they always agree with both.
Arguments
- data
A data frame.
- design
design_stratified(),design_spread()ordesign_weighted()withstrata, ordesign_certainty()whoserestis one of these. For the last the table describesrestover the rows below the threshold, and the rows at or above it, which are taken with certainty, are not counted in any stratum. Other designs are refused.
Value
A data frame with one row per stratum of data, in key order (see
design_stratified()): the strata columns, then
NRows in the stratum.
nRows drawn from it.
probThe inclusion probability of each of its rows, as
inclusion_prob()gives it.NAfordesign_spread()withsizeand fordesign_weighted(), whose rows in one stratum have different probabilities; thereinclusion_prob()gives them row by row.sdUnder Neyman allocation, the stratum's standard deviation that the split used: of the
allocation_bycolumn within the stratum, or as given.NAunder other allocations.costThe cost of one row, when the design has
cost, andNAotherwise.statusWhy the stratum got
n:"rule"for its share under the allocation rule, rounded;"count"for a count given inallocation;"floor"for a stratum raised tomin_per_stratumfrom a smaller share;"capped"for one the rule asked more rows of than it holds, so it is taken whole and the rows it could not give go to the other strata;"take-all"for one taken whole for another reason, such as a size belowmin_per_stratumor a count equal to its size; and"empty"for one allocated no rows, whose rows can never be drawn. Withreplace = TRUEno stratum is capped or taken whole.
Examples
df <- data.frame(id = 1:300,
site = rep(c("a", "b", "c", "d"), c(150, 100, 45, 5)),
v = c(1:150 %% 7, 1:100 %% 19, 1:45 %% 3, 1:5 * 40))
d <- design_stratified("site", n = 30, allocation = "neyman",
allocation_by = "v", min_per_stratum = 2)
allocation_table(df, d)
#> site N n prob sd cost status
#> 1 a 150 8 0.05333333 1.9948592 NA rule
#> 2 b 100 15 0.15000000 5.5331873 NA rule
#> 3 c 45 2 0.04444444 0.8257228 NA floor
#> 4 d 5 5 1.00000000 63.2455532 NA capped
# The same counts as a draw, and the same probabilities as inclusion_prob()
table(draw(df, d, seed = 1)$site)
#>
#> a b c d
#> 8 15 2 5
tapply(inclusion_prob(df, d), df$site, unique)
#> a b c d
#> 0.05333333 0.15000000 0.04444444 1.00000000