Iterative proportional fitting. Each margin is enforced in turn and the cycle repeats until every margin is matched within tolerance. Raking is the usual way to make a sample agree with published counts for a small group when the joint distribution of those counts is not published, only the one-way totals.
Arguments
- data
A data frame containing the raking variables.
- margins
A named list; each element is a named numeric vector of population totals for the levels of the corresponding column of
data.- weights
Starting weights. Default
NULLfor unit weights.- max_iter
Maximum number of cycles. Default
50.- tol
Convergence tolerance on the largest absolute margin discrepancy. Default
1e-8.
Examples
df <- data.frame(
region = c("north", "north", "south", "south"),
group = c("a", "b", "a", "b")
)
morie_rake(df, list(region = c(north = 60, south = 40),
group = c(a = 70, b = 30)))
#> $weights
#> [1] 42 18 28 12
#>
#> $converged
#> [1] TRUE
#>
#> $iterations
#> [1] 1
#>
#> $max_discrepancy
#> [1] 0
#>
