# Load required packages and data
library(dplyr)
data(survey_data)
# Basic two-sample test
survey_data %>%
t_test(life_satisfaction, group = gender)
# With survey weights
survey_data %>%
t_test(life_satisfaction, group = gender, weights = sampling_weight)
# Multiple variables
survey_data %>%
t_test(age, income, life_satisfaction, group = region, weights = sampling_weight)
# One-sample test against a benchmark
survey_data %>%
t_test(life_satisfaction, mu = 5, weights = sampling_weight)
# Grouped analysis
survey_data %>%
group_by(region) %>%
t_test(life_satisfaction, group = gender, weights = sampling_weight)
# Equal variance assumption
survey_data %>%
t_test(life_satisfaction, group = gender, var.equal = TRUE)
# One-sided test
survey_data %>%
t_test(income, group = gender, alternative = "greater")
# Using tidyselect helpers
survey_data %>%
t_test(starts_with("trust"), group = gender, weights = sampling_weight)
# Store results for further analysis
result <- survey_data %>%
t_test(life_satisfaction, group = gender, weights = sampling_weight)
print(result)
# --- Three-layer output ---
result <- t_test(survey_data, life_satisfaction, group = gender)
result # compact one-line summary
summary(result) # full detailed output with all sections
summary(result, effect_sizes = FALSE) # hide effect sizes
Run the code above in your browser using DataLab