Learn R Programming

scf (version 1.0.5)

scf_prop_test: Test a Proportion in SCF Data

Description

Tests a binary variable's proportion against a null hypothesis (one-sample), or compares proportions across two groups (two-sample). Supports two-sided, less-than, or greater-than alternatives.

Usage

scf_prop_test(
  design,
  var,
  group = NULL,
  p = 0.5,
  alternative = c("two.sided", "less", "greater"),
  conf.level = 0.95
)

Value

An object of class "scf_prop_test" with:

results

A data frame with the pooled estimate, standard error, z-statistic, p-value, confidence interval, and significance stars.

proportions

(Only in two-sample tests) A data frame of pooled proportions by group.

fit

A list describing the method, null value, alternative hypothesis, and confidence level.

Arguments

design

A scf_mi_survey object created by scf_load(). Must contain replicate-weighted implicates.

var

A one-sided formula indicating a binary variable (e.g., ~rich).

group

Optional one-sided formula indicating a binary grouping variable (e.g., ~female). If omitted, a one-sample test is performed.

p

Null hypothesis value. Defaults to 0.5 for one-sample, 0 for two-sample tests.

alternative

Character. One of "two.sided" (default), "less", or "greater".

conf.level

Confidence level for the confidence interval. Default is 0.95.

Statistical Notes

Proportions are computed in each implicate using weighted means, and variances are approximated under the binomial model. Rubin’s Rules are applied to pool point estimates and standard errors. For pooling details, see scf_MIcombine().

See Also

scf_ttest(), scf_mean(), scf_MIcombine()

Examples

Run this code
# Do not implement these lines in real analysis:
# Use functions `scf_download()` and `scf_load()`
td <- tempfile("proptest_")
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)

# Wrangle data for example
scf2022 <- scf_update(scf2022,
  rich   = networth > 1e6,
  female = factor(hhsex, levels = 1:2, labels = c("Male","Female")),
  over50 = age > 50
)

# Example for real analysis: One-sample test
scf_prop_test(scf2022, ~rich, p = 0.10)

# Example for real analysis: Two-sample test
scf_prop_test(scf2022, ~rich, ~female, alternative = "less")

# 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