Learn R Programming

migest (version 2.0.5)

net_matrix_lp: Estimate Migration Flows to Match Net Totals via Linear Programming

Description

Solves for an origin-destination flow matrix that satisfies directional net migration constraints while minimizing the total absolute deviation from a prior matrix. This method uses linear programming with split variables to minimize L1 error, optionally respecting a structural zero mask.

Usage

net_matrix_lp(net_tot, m, zero_mask = NULL, tol = 1e-06)

Value

A named list with components:

n

Estimated matrix of flows satisfying the net constraints.

it

Number of iterations (always 1 for LP method).

tol

Tolerance used for checking net flow balance.

value

Total L1 deviation from prior matrix m.

convergence

Logical indicator of successful solve.

message

Text summary of convergence status.

Arguments

net_tot

A numeric vector of net migration totals for each region. Must sum to zero.

m

A square numeric matrix providing prior flow estimates. Must have dimensions length(net_tot) × length(net_tot).

zero_mask

A logical matrix of the same dimensions as m, where TRUE indicates forbidden (structurally zero) flows. Defaults to disallowing diagonal flows.

tol

A numeric tolerance for checking that sum(net_tot) == 0. Default is 1e-6.

Details

This function uses lpSolve::lp() to solve a linear program. The estimated matrix minimizes the sum of absolute deviations from the prior matrix m, subject to directional net flow constraints: $$\sum_j x_{ji} - \sum_j x_{ij} = \text{net}_i$$ Structural zeros are enforced by the zero_mask. All flows are constrained to be non-negative.

See Also

net_matrix_entropy() for KL divergence minimization, net_matrix_ipf() for iterative proportional fitting (IPF), and net_matrix_optim() for least-squares (L2) flow estimation.

Examples

Run this code
m <- matrix(c(0, 100, 30, 70,
              50,   0, 45,  5,
              60,  35,  0, 40,
              20,  25, 20,  0),
            nrow = 4, byrow = TRUE,
            dimnames = list(orig = LETTERS[1:4], dest = LETTERS[1:4]))
addmargins(m)
sum_region(m)

net <- c(30, 40, -15, -55)
result <- net_matrix_lp(net_tot = net, m = m)
result$n |>
  addmargins() |>
  round(2)
sum_region(result$n)

Run the code above in your browser using DataLab