allowNegsnoMargin: Raking Algorithm Function A: when negative values are allowed

allowNegsnoMarginR Documentation

Raking Algorithm Function A: when negative values are allowed

Description

When raking, the appropriate algorithm is chosen (negative values allowed or not, margin needed or not), "whole people" adjustments to be made to selected cells in a row are calculated, then "residual people" adjustments to be made to selected cells in a row are calculated, then column control totals are reconciled. Raking is run iteratively row-by-row. Regardless of the algorithm needed, five arguments are needed. A sixth argument, "needMargin" is only needed for algorithm C (noNegsneedMargin). This is a helper function used in dbRake when negative values ARE allowed.

Usage

allowNegsnoMargin(CurrRow, CurrRow_value, data, n_colGrps, n_rowGrps, RowAdj)

Arguments

CurrRow

a subset of data with 3 rows and columns: XXX, n_colGrps, Sum, Ctrl_TOTAL, Diff, adj_value, where XXX is Sex in Part 1, Region in Part 2, and Age in Part 3. The rows are the one XXX row currently being worked on, Adjustments, and AdjCurrRow.

CurrRow_value

a counter to iterate through rows in data

data

a dataframe of rows to be iteratively raked with columns: XXX, n_colGrps, Sum, Ctrl_TOTAL, Diff, adj_value, where XXX is the variable being raked (Sex in Part 1, Region in Part 2, Age in Part 3). Rows are the rows of XXX as well as three summary rows: Sum, Ctrl_TOTAL, Diff.

n_colGrps

the number of column groups to rake over (e.g., 89 LHAs, number of Age Groups, etc.)

n_rowGrps

the number of rows groups to rake over (e.g., 2 Sexes, 89 LHAs, etc.)

RowAdj

vector of zeros, of length n_colGrps (e.g., 89 zeros, etc.)

Value

original dataframe, but with CurrRow's Diff now 0, and any adjustments made to CurrRow reversed in the row below that has the largest minimum value

See Also

The overall raking function: dbRake()

Other raking helpers: add.random.fraction.to.cols(), adjustSex(), calc.cols(), multiRake(), noNegsneedMargin(), noNegsnoMargin(), prep.prorate.col(), prorate.col(), prorate.row(), prorate(), read.inputs(), real.to.int(), rename.age.grps(), rounded()


bcgov/dbutils documentation built on Sept. 30, 2022, 12:04 a.m.