calc.cols: Calculate necessary columns

calc.colsR Documentation

Calculate necessary columns

Description

calculates necessary columns (Sum, Ctrl_TOTAL, Diff, adj_value) in preparation for prorating rows or raking. First, it calculates the actual sum (of columns), then adds in VarRow control totals, then calculates the difference, and finally calculates the adjustment value (difference divided by number of groups). This is a helper function used in dbRake, and before calling prorate.row.

Usage

calc.cols(data, temp, VarRow, n_colGrps)

Arguments

data

a dataframe of initial population counts that need to be adjusted to control totals (e.g., columns: a region variable ("VarRow"), 1 (for Males), 2 (for Females))

temp

a dataframe of control totals to adjust data to (e.g., region control totals)

VarRow

the name of the variable to join temp to data (e.g., VarRow for "LHA")

n_colGrps

the number of groups to adjust over (e.g., number of Sexes, 2); this is essentially the number of columns in data minus 1 (for the VarRow column)

Details

This function is first called in dbRake Part 1 to update initial initial estimates of male/female regional total values (before prorating rows, and again before raking), then again in Part 2 to update initial 5 year age group and maximum age group estimates by Sex (before prorating rows, and again before raking), and finally in Part 3 to update initial single year of age estimates by Sex (before prorating rows, and again before raking).

Value

the original dataframe with four new columns (Sum, Ctrl_TOTAL, Diff, adj_value)

See Also

The overall raking function: dbRake()

Other raking helpers: add.random.fraction.to.cols(), adjustSex(), allowNegsnoMargin(), 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.