fienberg: Fienberg rebalancing for two vectors with a given starting...

View source: R/fienberg.R

fienbergR Documentation

Fienberg rebalancing for two vectors with a given starting matrix

Description

Fienberg rebalancing for two vectors with a given starting matrix

Usage

fienberg(start_mat, target_from, target_to)

Arguments

start_mat

An n by n matrix with non-negative elements and row sums equal to 1.

target_from

An n by 1 vector with values >=0.

target_to

An n by 1 vector with values >=0. The sum of target_from must be equal to the sum of target_to.

Implements a specific version of the iterative proportional fitting algorithm. Given an n by n matrix start_mat, the algorithm rebalances it so that the target_from * start_mat = target_to. This is done by an iterative fitting algorithm.

Value

The rebalanced n by n matrix start_mat.

Examples

set.seed(123)
n = 10
vec0 = runif(n) * 10
vec1 = runif(n); vec1 = vec1 / sum(vec1) * sum(vec0)
matA = diag(n) + 10^-8; matA = matA / rowSums(matA)

res = fienberg(start_mat=matA,target_from=vec0,target_to=vec1)

tkrisztin/downscalr documentation built on June 2, 2025, 1:16 a.m.