# Load required packages and data
library(dplyr)
data(survey_data)
# Basic correlation between two variables
survey_data %>%
spearman_rho(life_satisfaction, political_orientation)
# Correlation matrix for multiple variables
survey_data %>%
spearman_rho(life_satisfaction, political_orientation, trust_media)
# Weighted correlations (mathematically correct, though SPSS may not apply weights)
survey_data %>%
spearman_rho(age, income, weights = sampling_weight)
# Grouped correlations
survey_data %>%
group_by(region) %>%
spearman_rho(age, income, life_satisfaction)
# Using tidyselect helpers
survey_data %>%
spearman_rho(starts_with("trust"), weights = sampling_weight)
# Listwise deletion for missing data
survey_data %>%
spearman_rho(age, income, use = "listwise")
# One-tailed test
survey_data %>%
spearman_rho(age, income, alternative = "greater")
# --- Three-layer output ---
result <- spearman_rho(survey_data, age, income, life_satisfaction)
result # compact one-line overview
summary(result) # full correlation, p-value, and N matrices
summary(result, pvalue_matrix = FALSE) # hide p-values
Run the code above in your browser using DataLab