w_modus() finds the mode (most frequently occurring value) of your data
using survey weights for population-representative results. The mode tells you
which category or value is the most common in your population. This is
especially useful for categorical variables (e.g., the most common education
level, the most frequent employment status).
Unlike mean and median, the mode works with both numeric and categorical data.
Arguments
- data
Your survey data (a data frame or tibble)
- ...
The variables you want to analyze. Works best with categorical or discrete numeric variables. You can list multiple variables or use helpers like
starts_with("trust")- weights
Survey weights to make results representative of your population. Without weights, the mode is simply the most frequent value in your sample.
- na.rm
Remove missing values before calculating? (Default: TRUE)
Value
Population-weighted mode(s) with sample size information, including the most common value (by weighted frequency), effective sample size (effective N), and the number of valid observations used.
Details
Understanding the Results
Weighted Mode: The value that occurs most frequently in the weighted population. For weighted data, the mode is the value whose observations have the largest total weight.
Effective N: How many independent observations your weighted data represents.
N: The actual number of observations used.
If multiple values share the highest weighted frequency (ties), the first value encountered is returned.
See also
w_median for the weighted middle value.
w_mean for weighted means.
frequency for complete frequency tables of categorical variables.
describe for comprehensive descriptive statistics including the mode.
Other weighted_statistics:
w_iqr(),
w_kurtosis(),
w_mean(),
w_median(),
w_quantile(),
w_range(),
w_sd(),
w_se(),
w_skew(),
w_var()
Examples
# Load required packages and data
library(dplyr)
data(survey_data)
# Basic weighted mode (most frequent value)
survey_data %>% w_modus(gender, weights = sampling_weight)
#>
#> Weighted Mode Statistics
#> ------------------------
#> # A tibble: 1 × 3
#> Variable weighted_mode effective_n
#> <chr> <fct> <dbl>
#> 1 gender Female 2469.
#>
# Multiple variables (works best with categorical/discrete data)
survey_data %>% w_modus(gender, region, weights = sampling_weight)
#>
#> Weighted Mode Statistics
#> ------------------------
#> # A tibble: 2 × 3
#> Variable weighted_mode effective_n
#> <chr> <chr> <dbl>
#> 1 gender Female 2469.
#> 2 region West 2469.
#>
# Grouped data
survey_data %>% group_by(region) %>% w_modus(gender, weights = sampling_weight)
#>
#> Weighted Mode Statistics
#> ------------------------
#>
#> Group: region = East
#> # A tibble: 1 × 2
#> weighted_mode effective_n
#> <fct> <dbl>
#> 1 Female 477
#>
#> Group: region = West
#> # A tibble: 1 × 2
#> weighted_mode effective_n
#> <fct> <dbl>
#> 1 Female 1993.
#>
# In summarise context
survey_data %>% summarise(mode_gender = w_modus(gender, weights = sampling_weight))
#> # A tibble: 1 × 1
#> mode_gender
#> <fct>
#> 1 Female
# Unweighted (for comparison)
survey_data %>% w_modus(gender)
#>
#> Mode Statistics
#> ---------------
#> # A tibble: 1 × 3
#> Variable mode n
#> <chr> <chr> <dbl>
#> 1 gender Female 2500
#>
