single_adjust: Adjust weights based on current imbalance of a single...

View source: R/rake.R

single_adjustR Documentation

Adjust weights based on current imbalance of a single variable.

Description

This function internally rakes the weights provided according to the current imbalance in a single variable. The mathematical process here is simple: for each level of the variable, multiply the weight by the target proportion divided by the current weighted proportion. For instance, if a party variable should be 0.4 Independent, 0.35 Democratic, and 0.25 Republican, and the current weighted proportion is 0.4 Democratic, then the weights of every Democrat will be multiplied by 0.35 / 0.4. This is an internal function and not intended for end-users.

Usage

single_adjust(data, weights, target, var, cache)

Arguments

data

The data frame (tibble) or matrix which contains the original data.

weights

The current weights

target

The target proportions, specified as in harvest

var

A quoted character vector containing the variable we are currently raking on.

cache

A list of integer vectors mapping rows of the data frame to levels of the target variable

Value

Adjusted weights, raked for this variable.


aaronrudkin/autumn documentation built on Feb. 5, 2024, 6:08 p.m.