Description Usage Arguments Value Examples
This function creates row-level weights using an iterative raking algorithm based
on targets from a known population (established with universe()
).
The weights are appended as a new column in the data. If iterake()
converges, the weighted marginal proportions of the sample will match those
set in universe()
. Summary statistics of the weighting procedure are
presented by default.
1 2 3 |
universe |
Output object created with |
wgt.name |
Name given to column of weights to be added to data, default is "weight", optional. |
max.wgt |
Maximum value weights can take on, default is 3, optional. The capping
takes place prior to applying expansion factor (if |
threshold |
Value specifying minimum summed difference between weighted marginal proportions of sample and universe before algorithm quits, default is 1e-10, optional. |
max.iter |
Value capping number of iterations for the procedure, default is 50, optional. |
stuck.limit |
Value capping the number of times summed differences between sample and universe can oscillate between increasing and decreasing, default is 5, optional. |
permute |
Boolean indicating whether to test all possible orders of categories in |
summary |
Whether or not to display summary output of the procedure, default is |
Data frame with the resulting weight variable appended to it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | data(demo_data)
iterake(
universe = universe(
data = demo_data,
category(
name = "Sex",
buckets = factor(
x = levels(demo_data[["Sex"]]),
levels = levels(demo_data[["Sex"]])
),
targets = c(0.4, 0.5),
sum.1 = TRUE
),
category(
name = "BirthYear",
buckets = c(1986:1990),
targets = rep(0.2, times = 5)
),
category(
name = "EyeColor",
buckets = c("brown", "green", "blue"),
targets = c(0.8, 0.1, 0.1)
),
category(
name = "HomeOwner",
buckets = c(TRUE, FALSE),
targets = c(3/4, 1/4)
)
)
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.