Learn R Programming

ipfr

A package for iterative proportional fitting on multiple marginal distributions in R. The goal of this package is to make survey raking, matrix balancing, and population synthesis easier.

Installation

Install the latest official version from CRAN:

install.packages("ipfr")

Install the development version of the package:

library(devtools)
install_github("dkyleward/ipfr", build_vignettes = TRUE)

Basic Usage

(See vignettes at the bottom for advanced topics.)

A basic matrix balance task:

mtx <- matrix(data = runif(9), nrow = 3, ncol = 3)
row_targets <- c(3, 4, 5)
column_targets <- c(5, 4, 3)
result <- ipu_matrix(mtx, row_targets, column_targets)

A basic survey balance task:

survey <- tibble(
  size = c(1, 2, 1, 1),
  autos = c(0, 2, 2, 1),
  weight = 1
)
targets <- list()
targets$size <- tibble(
  `1` = 75,
  `2` = 25
)
targets$autos <- tibble(
  `0` = 25,
  `1` = 50,
  `2` = 25
)
result <- ipu(survey, targets)

Creating synthetic households from the ipu() result:

synthesize(result$weight_tbl)

Vignettes

Using ipfr: https://cran.r-project.org/web/packages/ipfr/vignettes/using_ipfr.html
Common ipf problems: https://cran.r-project.org/web/packages/ipfr/vignettes/common_ipf_problems.html

Copy Link

Version

Install

install.packages('ipfr')

Monthly Downloads

232

Version

1.0.2

License

Apache License (== 2.0)

Issues

Pull Requests

Stars

Forks

Maintainer

Kyle Ward

Last Published

April 1st, 2020

Functions in ipfr (1.0.2)

balance_secondary_targets

Balances secondary targets to primary
create_target_priority

Create a named list of target priority levels.
check_geo_fields

Check geo fields
check_tables

Check seed and target tables for completeness
process_seed_table

Helper function to process a seed table
compare_results

Compare results to targets
scale_targets

Scale targets to ensure consistency
ipfr

ipfr: A package to perform iterative proportional fitting
ipf

Re-weight a Seed Table to Marginal Controls
ipu

Iterative Proportional Updating
setup_arizona

Create the ASU example
synthesize

Creates a synthetic population based on ipu results
check_missing_categories

Check for missing categories in seed
adjust_factor

Applies an importance weight to an ipfr factor
ipu_nr

Iterative Proportional Updating (Newton-Raphson)
ipu_matrix

Balance a matrix given row and column targets