Learn R Programming

scf (version 1.0.4)

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)

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.

Implementation

This function wraps scf_percentile() with q = 0.5. The user provides a scf_mi_survey object and a one-sided formula indicating the variable of interest. An optional grouping variable can be specified with a second formula. Output includes pooled medians, standard errors, min/max across implicates, and implicate-level values.

Statistical Notes

Median estimates are not pooled using Rubin’s Rules. Following SCF protocol, the function calculates the median within each implicate and averages across implicates. See the data set's official codebook.

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  <- tempdir()
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("scf2022.rds", force = TRUE)

Run the code above in your browser using DataLab