Learn R Programming

scf (version 1.0.5)

scf_ttest: T-Test of Means using SCF Microdata

Description

Tests whether the mean of a continuous variable differs from a specified value (one-sample), or whether group means differ across a binary factor (two-sample). Estimates and standard errors are computed using svymean() within each implicate, then pooled using Rubin’s Rules. Use this function to test hypotheses about means in the SCF microdata.

Usage

scf_ttest(
  design,
  var,
  group = NULL,
  mu = 0,
  alternative = c("two.sided", "less", "greater"),
  conf.level = 0.95
)

Value

An object of class scf_ttest with:

results

A data frame with pooled estimate, standard error, t-statistic, degrees of freedom, p-value, and confidence interval.

means

Group-specific means (for two-sample tests only).

fit

List describing the test type, null hypothesis, confidence level, and alternative.

Arguments

design

A scf_mi_survey object created by scf_load().

var

A one-sided formula specifying a numeric variable (e.g., ~income).

group

Optional one-sided formula specifying a binary grouping variable (e.g., ~female).

mu

Numeric. Null hypothesis value. Default is 0.

alternative

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

conf.level

Confidence level for the confidence interval. Default is 0.95.

See Also

scf_prop_test(), 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("ttest_")
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: Derive analysis vars
scf2022 <- scf_update(scf2022,
  female = factor(hhsex, levels = 1:2, labels = c("Male","Female")),
  over50 = age > 50
)

# Example for real analysis:  One-sample t-test
scf_ttest(scf2022, ~income, mu = 75000)

# Example for real analysis:  Two-sample t-test
scf_ttest(scf2022, ~income, group = ~female)

# 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