check_targets: Check the targets and seed for compatibility before running...

Description Usage Arguments Value Examples

Description

In IPFs, common subtotals in each target must be equal, otherwise the IPF will not converge on a single result. This function checks the common dimensions over each target combination for compatibility. Further, this function checks the IPF seed, if provided, for compabitibilty with the targets. If the seed, when summed over each dimension in a given target, contains any missing values or zero values, the target must also have a zero or missing value.

Usage

1
2
check_targets(targets, seed = NULL, target.value.names = "value",
  seed.value.name = "value", max.error = 0.01)

Arguments

targets

A list of data frames containing subtotal targets. All totals in each target should be equal. Series supplied in each target will shape the final data frame.

seed

An optional data frame of seed values containing all final dimensions expected as output of ip_fit(). Leave as NULL if the targets will be run using ip_expand() or will be used with a generic seed.

target.value.names

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

seed.value.name

The name of the series in seed containing values. Defaults to "value".

max.error

The maximum total absolute difference allowed between final scaled values and targets.

Value

Messages in the console and an output list of data frames containing any incompitable line items in the seed and targets.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
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(x = c(rep(letters[1], 5), rep(letters[2], 5)),
                   z = rep(letters[6:10], 2),
                   value = c(5, 10, 15, 20, 0, 10, 10, 10, 10, 10))

tar.list <- list(tar1, tar2, tar3)
check_targets(tar.list)

#This will find errors with the targets
tar3b <- data.frame(x = c(rep(letters[1], 5), rep(letters[2], 5)),
                   z = rep(letters[6:10], 2),
                   value = c(0, 10, 15, 20, 0, 10, 10, 10, 10, 10))

tar.list <- list(tar1, tar2, tar3b)
seed <- ipfitr::ip_create_seed(tar.list)
check_targets(tar.list, seed)

#This will find errors with the targets and the seed
seed2 <- seed %>% mutate(value = ifelse(x == "a" & z == "g", 0, value))
check_targets(tar.list, seed2)

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