Learn R Programming

scf (version 1.0.5)

scf_median: Estimate the Population Median of a Continuous SCF Variable

Description

Estimates the median (50th percentile) of a continuous SCF variable. Use this operation to characterize a typical or average value. In contrast to scf_mean(), this function is both uninfluenced by, and insensitive to, outliers.

Usage

scf_median(scf, var, by = NULL, verbose = FALSE)

Value

A list of class "scf_median" with:

results

A data frame with pooled medians, standard errors, and range across implicates.

imps

A list of implicate-level results.

aux

Variable and grouping metadata.

Arguments

scf

A scf_mi_survey object created by scf_load(). Must contain five implicates.

var

A one-sided formula specifying the continuous variable of interest (e.g., ~networth).

by

Optional one-sided formula for a categorical grouping variable.

verbose

Logical; if TRUE, show implicate-level results.

Implementation

This function wraps scf_percentile() with q = 0.5. The user supplies a scf_mi_survey object and a one-sided formula for the variable of interest, with an optional grouping formula. Output includes pooled medians, standard errors, min/max across implicates, and implicate-level values. Point estimates are the mean of the five implicate medians. Standard errors are computed using the Survey of Consumer Finances convention described below, not Rubin’s Rules.

Statistical Notes

Median estimates follow the Federal Reserve Board’s SCF variance convention. For each implicate, the median is computed with replicate weights via survey::svyquantile(). The pooled estimate is the average of the five implicate medians. The pooled variance is V_total = V1 + ((m + 1) / m) * B, where V1 is the replicate-weight sampling variance from the first implicate and B is the between-implicate variance of the five implicate medians, with m = 5 implicates. The reported standard error is sqrt(V_total). This matches the Federal Reserve Board's published SAS macro for SCF descriptive statistics and is not Rubin’s Rules.

See Also

scf_percentile(), scf_mean()

Examples

Run this code
# Do not implement these lines in real analysis:
# Use functions `scf_download()` and `scf_load()`
td <- tempfile("median_")
dir.create(td)

src <- system.file("extdata", "scf2022_mock_raw.rds", package = "scf")
file.copy(src, file.path(td, "scf2022.rds"), overwrite = TRUE)
scf2022 <- scf_load(2022, data_directory = td)

# Example for real analysis: Estimate medians
scf_median(scf2022, ~networth)
scf_median(scf2022, ~networth, by = ~edcl)

# Do not implement these lines in real analysis: Cleanup for package check
unlink(td, recursive = TRUE, force = TRUE)

Run the code above in your browser using DataLab