Learn R Programming

WIPF (version 0.1.0-3)

WIPF1: Weighted Iterative Proportional Fitting (WIPF) in one dimension

Description

Implements WIPF in one dimension. This function updates, using a set of weights, an initial 1-dimensional array, a vector (referred as the seed), to match a given value (referred as the margin), in such as way that the weighted sum of the updated values coincide with the margin.

Usage

WIPF1(
  seed,
  weights,
  margin = 1,
  normalize = TRUE,
  tol = 10^-6,
  maxit = 1000,
  full = FALSE,
  ...
)

Value

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 seed with the solution reached at convergence (or when the maximum number of iterations is reached).

iter

Number of iterations when the algorithm stops.

error.margins

An object similar to margin with the absolute differences between the values in margin and the weighted sum of the values in sol.

inputs

A list containing all the objects with the values used as arguments by the function.

Arguments

seed

A vector of non-negative values with the initial values.

weights

A vector of non-negative values with the weights associated to each component of seed and with the same length as seed.

margin

A non-negative scalar with the (weighted) marginal total to be fitted. Default, 1.

normalize

TRUE/FALSE argument indicating whether weights should be normalized to sum 1 before building the weighted sum to be compared with the margin value. Default, TRUE. Normalization is necessary when we want to adjust a set of indexes for which the margin correspond to other index that is a theoretical convex combination of the inner indexes. This characterizes a typical context where WIPF could be of value.

tol

Stopping criterion. The algorithm stops when the maximum absolute difference between the solutions obtained in two consecutive iteration is lower than the value specified by tol. Default, 0.000001.

maxit

Stopping criterion. A positive integer number indicating the maximum number of iterations allowed. Default, 1000. The algorithm will stop if the values to be fitted still has not converged after this many iterations.

full

TRUE/FALSE argument indicating if either only the solution should be shown or a more complete output.

...

Other arguments to be passed to the function. Not currently used.

Author

Jose M. Pavia, pavia@uv.es

Examples

Run this code
s <- c(1.0595723, 0.9754876, 0.8589494, 0.8589123)
w <- c(651301.9, 581185.1, 555610.8, 602595.6)
example <- WIPF1(seed = s, weights = w)

Run the code above in your browser using DataLab