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

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. A list of data frames containing subtotal targets for the datatable. All totals in each target should be equal. The names of the series in targets containing subtotals to scale. Can be string or array of strings. 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. The maximum number of iterations of scaling. Iterative scaling with end once this value is reached, even if the error is above max.error. 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. The name of the series of iced values in freeze_cells. 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. 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. An array of length 2 of the names of the minimum and maximum values in minmax_cells. 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. 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. A data frame of cell or slice targets with growth rates over listed dimensions. See ipfitr::ip_growth_transform for detail. The name of the series in datatable containing the values to be scaled. The name or names of the series of iced values in freeze_slice. 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

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)#> Initializing IPF... 3 targets supplied.#> Warning: Supplied targets do not have the same totals. IPF may not converge.#> Warning: Column x joining character vector and factor, coercing into character vector#> Warning: Column y joining character vector and factor, coercing into character vector#> Warning: Column z joining character vector and factor, coercing into character vector#> Iteration Summary: 1#>     Iteration Error:  20#> Iteration Summary: 2#>     Iteration Error:  20#> Iteration Summary: 3#>     Iteration Error:  20#> Iteration Summary: 4#>     Iteration Error:  20#> Iteration Summary: 5#>     Iteration Error:  20#> Iteration Summary: 6#>     Iteration Error:  20#> Iteration Summary: 7#>     Iteration Error:  20#> Iteration Summary: 8#>     Iteration Error:  20#> Iteration Summary: 9#>     Iteration Error:  20#> Iteration Summary: 10#>     Iteration Error:  20#> Iteration Summary: 11#>     Iteration Error:  20#> Iteration Summary: 12#>     Iteration Error:  20#> Iteration Summary: 13#>     Iteration Error:  20#> Iteration Summary: 14#>     Iteration Error:  20#> Iteration Summary: 15#>     Iteration Error:  20#> Iteration Summary: 16#>     Iteration Error:  20#> Iteration Summary: 17#>     Iteration Error:  20#> Iteration Summary: 18#>     Iteration Error:  20#> Iteration Summary: 19#>     Iteration Error:  20#> Iteration Summary: 20#>     Iteration Error:  20#> Iteration Summary: 21#>     Iteration Error:  20#> Iteration Summary: 22#>     Iteration Error:  20#> Iteration Summary: 23#>     Iteration Error:  20#> Iteration Summary: 24#>     Iteration Error:  20#> Iteration Summary: 25#>     Iteration Error:  20