diagnose_weights: Diagnose convergence of weighted data to targets

View source: R/diagnose_weights.R

diagnose_weightsR Documentation

Diagnose convergence of weighted data to targets

Description

This function assesses the convergence of data to target proportions given weights and returns diagnostic results.

Usage

diagnose_weights(data, target = NULL, weights = NULL)

Arguments

data

A data frame (tibble) or matrix containing all variables in the target argument. The data frame can contain additional variables.

target

A list of target proportions in the population of interest. This argument can be one of two formats: a list of named numeric vectors, or a data frame (tibble) with three columns (variable, variable level, and proportion) in order. No level may have a negative proportion or an NA, and each variable should sum to 1. If this argument is not provided, and data was constructed by harvest, then target will be read from environment.

weights

Optionally, a numeric vector of weights equal in length to the number of rows in data. If this argument is not provided, then data must contain a weight column named "weights" or one of the automatic names for weight columns generated by harvest

Value

A data frame with seven rows: "variable" (the variable among the target variables), "level" (the specific value of that variable), "prop_original" (the unweighted proportion in data), "prop_weighted" (the weighted proportion in data), "target" (the proportion expressed in target), "error_original" (absolute deviation in the unweighted data), "error_weighted" (absolute deviation in data after applying weights).

Examples

## Not run: 
# Sample pipe workflow
respondent_data %>%
  harvest(ns_target) %>%
  diagnose_weights()

# Explicit calls
result = harvest(respondent_data, ns_target)
diagnose_weights(data=result,
                 target=ns_target,
                 weights=result$weights)

## End(Not run)

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