Learn R Programming

mariposa (version 0.7.3)

pearson_cor: Measure How Strongly Variables Are Related

Description

pearson_cor() shows you how strongly numeric variables are related to each other. For example, is age related to income? Does satisfaction increase with experience? This helps you understand patterns in your data.

The correlation tells you:

  • Direction: Positive (both increase together) or negative (one increases as other decreases)

  • Strength: How closely the variables move together (from 0 = no relationship to 1 = perfect relationship)

  • Significance: Whether the relationship is real or could be due to chance

Usage

pearson_cor(
  data,
  ...,
  weights = NULL,
  conf.level = 0.95,
  alternative = c("two.sided", "less", "greater"),
  use = c("pairwise", "listwise"),
  na.rm = NULL
)

Value

Correlation results showing relationships between variables, including:

  • Correlation coefficient (r): Strength and direction of relationship

  • P-value: Whether the relationship is statistically significant

  • Confidence interval: Range of plausible correlation values

  • Sample size: Number of observations used Use summary() for the full SPSS-style output with toggleable sections.

Arguments

data

Your survey data (a data frame or tibble)

...

The numeric variables you want to correlate. List two for a single correlation or more for a correlation matrix.

weights

Optional survey weights for population-representative results. Following SPSS CORRELATIONS, the weighted degrees of freedom use n = sum(w) (not Kish's effective sample size). This is appropriate for normalized survey weights with mean \(\approx 1\). For raw expansion weights (e.g., summing to millions of population units), the resulting standard errors and confidence intervals will be drastically too narrow — in that case, normalize weights so that sum(w) == n, or use the survey package for design-based inference.

conf.level

Confidence level for intervals (Default: 0.95 = 95%)

alternative

Direction of the test: "two.sided" (default), "less", or "greater".

use

How to handle missing values:

  • "pairwise" (default): Use all available data for each pair

  • "listwise": Only use complete cases across all variables

na.rm

Deprecated. Use use instead.

Details

Understanding the Results

Correlation coefficient (r) ranges from -1 to +1:

  • +1: Perfect positive relationship (as one goes up, the other always goes up)

  • 0: No linear relationship

  • -1: Perfect negative relationship (as one goes up, the other always goes down)

Interpreting strength (absolute value of r):

  • 0.00 - 0.10: Negligible relationship

  • 0.10 - 0.30: Weak relationship

  • 0.30 - 0.50: Moderate relationship

  • 0.50 - 0.70: Strong relationship

  • 0.70 - 0.90: Very strong relationship

  • 0.90 - 1.00: Extremely strong relationship

P-value interpretation:

  • p < 0.001: Very strong evidence of a relationship

  • p < 0.01: Strong evidence of a relationship

  • p < 0.05: Moderate evidence of a relationship

  • p >= 0.05: No significant relationship found

A correlation of 0.65 with p < 0.001 means:

  • Strong positive relationship (r = 0.65)

  • As one variable increases, the other tends to increase

  • Very unlikely to be due to chance (p < 0.001)

  • About 42% of variation is shared (r-squared = 0.65 squared = 0.42)

When to Use This

Use Pearson correlation when:

  • Both variables are numeric and continuous

  • You expect a linear relationship

  • Data is roughly normally distributed

  • You want to measure strength of linear association

Don't use when:

  • Data has extreme outliers (consider Spearman instead)

  • Relationship is curved/non-linear

  • Variables are categorical (use chi-squared test)

  • You need to establish causation (correlation does not imply causation)

Tips for Success

  • Always plot your data first to check for non-linear patterns

  • Consider both statistical significance (p-value) and practical importance (r value)

  • Remember: correlation does not imply causation

  • Check for outliers that might inflate or deflate correlations

  • Use Spearman correlation for ordinal data or non-normal distributions

References

Cohen, J. (1988). Statistical Power Analysis for the Behavioral Sciences (2nd ed.). Lawrence Erlbaum Associates.

Fisher, R. A. (1915). Frequency distribution of the values of the correlation coefficient in samples from an indefinitely large population. Biometrika, 10(4), 507--521.

See Also

cor for the base R correlation function.

cor.test for correlation significance testing.

spearman_rho for rank-based correlation (robust to outliers).

kendall_tau for ordinal correlation.

summary.pearson_cor for detailed output with toggleable sections.

Other correlation: kendall_tau(), partial_cor(), spearman_rho()

Examples

Run this code
# Load required packages and data
library(dplyr)
data(survey_data)

# Basic correlation between two variables
survey_data %>%
  pearson_cor(age, income)

# Correlation matrix for multiple variables
survey_data %>%
  pearson_cor(age, income, life_satisfaction)

# Weighted correlations
survey_data %>%
  pearson_cor(age, income, weights = sampling_weight)

# Grouped correlations
survey_data %>%
  group_by(region) %>%
  pearson_cor(age, income, life_satisfaction)

# Using tidyselect helpers
survey_data %>%
  pearson_cor(where(is.numeric), weights = sampling_weight)

# Listwise deletion for missing data
survey_data %>%
  pearson_cor(age, income, use = "listwise")

# --- Three-layer output ---
result <- survey_data %>%
  pearson_cor(age, income, life_satisfaction, weights = sampling_weight)
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