ip_fit: Iterative proportional fitting to scale seed values to...

Description Usage Arguments Value Examples

Description

Iterative proportional fitting to scale seed values to multiple target subtotals.

Usage

1
2
3
4
5
6
7
8
9
ip_fit(datatable, targets, datatable.value.name = "value",
  target.value.names = "value", max.error = 0.01,
  max.iterations = 25, freeze_cells = NULL,
  freeze_cells.value.name = "value", freeze_slice = NULL,
  freeze_slice.value.names = "value", minmax_cells = NULL,
  minmax_cells.value.names = c("value_min", "value_max"),
  minmax_slice = NULL, minmax_slice.value.names = c("value_min",
  "value_max"), minmax.smash.param = 1/3, growth_targets = NULL,
  save.tars = FALSE, show.messages = TRUE)

Arguments

datatable

A data frame of values to be scaled to targets.

targets

A list of data frames containing subtotal targets for the datatable. All totals in each target should be equal.

target.value.names

The names of the series in targets containing subtotals to scale. Can be string or array of strings.

max.error

The maximum total absolute difference allowed between final scaled values and targets. Iterative scaling will complete once the error is below this threshold or max.iterations occur.

max.iterations

The maximum number of iterations of scaling. Iterative scaling with end once this value is reached, even if the error is above max.error.

freeze_cells

Optional data frame of values with same series columns as datatable, specifying exact values to hit in the scaling. Any rows or values not listed, or NAs, will be scaled as normal.

freeze_cells.value.name

The name of the series of iced values in freeze_cells.

freeze_slice

Optional data frame containing subtotal targets for the datatable. Unlike targets, these data frames can be subsets only containing subtotals for one or more rows. Any rows or values not listed, or NAs, will be scaled as normal. Using freeze_slice for partial targets will increase the number of required iterations for scaling. This may require the user to increase the value of max.iterations. Separate elements of a dimension within a single cell using " + " to scale subtotals.

minmax_cells

Optional data frame of values with same series columns as datatable, specifying bounded values to hit in the scaling. Provide minimumn and maximum values for a cell to be scaled. Any rows or values not listed, or NAs, will be scaled as normal.

minmax_cells.value.names

An array of length 2 of the names of the minimum and maximum values in minmax_cells.

minmax_slice

Optional data frame containing subtotal targets for the datatable, specifying bounded values to hit in the scaling. Provide minimumn and maximum values for a slice of the data frame to be scaled. Unlike targets, these data frames can be subsets only containing subtotals for one or more rows. Any rows or values not listed, or NAs, will be scaled as normal. Using minmax_slice for partial targets will increase the number of required iterations for scaling. This may require the user to increase the value of max.iterations.

minmax.smash.param

Numeric value of 0 < x < 1. Following an out-of-bounds occurence for minmax_cells, the minmax.smash.param is the additional value added to the scaled value to bring it back into bounds. Values close to 0 bind the value to the violated bound, while close to 1 bind the value to the other bound. Values closer to0 will require more iterations to complete.

growth_targets

A data frame of cell or slice targets with growth rates over listed dimensions. See ipfitr::ip_growth_transform for detail.

datatable.value.names

The name of the series in datatable containing the values to be scaled.

freeze_slice.value.name

The name or names of the series of iced values in freeze_slice.

minmax_slice.value.name

The name or names of the series of the minimum and maximum values in minmax_slice.

Value

A dataframe with the same dimensionality as datatable, with all values scaled to the subtotals specified in each data frame in targets.

Examples

1
2
3
4
5
6
tar1 <- data.frame(x = letters[1:2], value = c(50, 50))
tar2 <- data.frame(y = letters[3:5], value = c(20, 40, 40))
tar3 <- data.frame(z = letters[6:10], value = c(10, 20, 30, 40, 10))

tar.list <- list(tar1, tar2, tar3)
df <- ip_create_seed(tar.list) %>% ip_fit(tar.list)

ryantimpe/ipfitr documentation built on May 14, 2019, 8:55 a.m.