| WIPF2 | R Documentation |
Implements WIPF in two dimensions. This function updates an initial
2-dimensional array (a matrix, referred to as the seed) using a matrix
of weights to align with a set of two vectors (referred to as the margins),
where one of them can be missing. When margin1 and margin2 are compatible
given the weights, the updated values ensure that the weighted sum
across columns matches margin1 and the weighted sum across rows
matches margin2.
If the margins are incompatible given the weights, the function WIPF1
is applied to the initial margins to make them compatible. In those cases,
margins are updated (are made compatible) in increasing order of sub-indices
(i.e., margin2 is adjusted to make it compatible with margin1).
WIPF2(
seed,
weights,
margin1,
margin2,
normalize = TRUE,
tol = 10^-6,
maxit = 1000,
full = FALSE,
...
)
seed |
A (RxC) matrix of non-negative values with the initial values. |
weights |
A (RxC) matrix of non-negative values with the weights associated to each entry of the matrix. |
margin1 |
A R-length vector of positive values with the target (weighted) marginal sums across columns to be fitted. |
margin2 |
A C-length vector of positive values with the target (weighted) marginal sums across rows to be fitted. |
normalize |
|
tol |
Stopping criterion. The algorithm stops when the maximum difference between the weighted sum(s) of
the values to be fitted and the margin(s) is lower than the value specified by |
maxit |
Stopping criterion. A positive integer number indicating the maximum number of iterations
allowed. Default, |
full |
|
... |
Other arguments to be passed to the function. Not currently used. |
When full = FALSE an object similar to seed with the solution reached when the algorithm stops.
When full = TRUE a list with the following components:
sol |
An object similar to |
iter |
Number of iterations when the algorithm stops. |
margin1 |
A R-length vector of positive values with the actual margin1 object used to reach the solution.
This coincides with |
margin2 |
A C-length vector of positive values with the actual margin2 object used to reach the solution.
This coincides with |
dev.margins |
A list with a set of objects similar to the margins with absolute maximum deviations
between the values in margins and the corresponding weighted sums of the values in |
dev.congruence |
A list with a set of objects similar to the margins containing the differences between the final margins actually used (after adjusting them, if necessary, to be compatible with the weights) and the original margins provided by the user. |
inputs |
A list containing all the objects with the values used as arguments by the function. |
Weighted Iterative proportional fitting is an extension of IPF. WIPF produces the same solutions than IPF with all weights being ones and when they are not normalized. IPF is also known as RAS in economics, raking in survey research or matrix scaling in computer science.
Jose M. Pavia, pavia@uv.es
s <- structure(c(1.1279, 1.1304, 1.0304, 0.8554, 1.5606, 1.4171, 1.2862,
1.2472, 1.0746, 1.0796, 0.9806, 0.928, 1.1607, 1.2436, 1.2191,
1.0786, 1.0194, 1.1716, 0.9937, 0.8611, 1.0172, 1.2511, 1.1606,
1.1959), .Dim = c(4L, 6L))
w <- structure(c(72161.97, 93725.94, 84408.83, 172774.13, 52875.08,
31936.92, 14191.44, 12595.46, 291698.94, 231408.32,
221763.43, 235217.74, 42028.56, 64458.09, 93443.13,
60348.74, 222482.04, 103695.94, 57066.82, 48657.48,
9572.75, 75745.02, 83912.38, 94019.92), .Dim = c(4L, 6L))
m1 <- c(1.110737, 1.029947, 0.934799, 0.906475)
m2 <- c(0.810992, 1.375921, 1.071519, 1.045006, 0.949938, 0.915762)
example <- WIPF2(seed = s, weights = w, margin1 = m1, margin2 = m2, full = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.