
Professional statistical analysis for survey data in R.
mariposa (Marburg Initiative for Political and Social
Analysis) provides 80 functions for importing, managing,
transforming, and analyzing survey data. Covers the full workflow from
data import (SPSS, Stata, SAS, Excel) through label management,
recoding, and standardization to statistical analysis with survey
weights, grouped operations via dplyr::group_by(), and
publication-ready output. Statistical results are validated against SPSS
v29 within documented per-tier tolerances; see
vignette("spss-compatibility") for per-function status.
# Install from GitHub
devtools::install_github("YannickDiehl/mariposa")library(mariposa)
library(dplyr)
# Load example survey data (2,500 respondents)
data(survey_data)
# Interactive HTML codebook in RStudio Viewer
codebook(survey_data)
# Descriptive statistics with survey weights
survey_data %>%
describe(age, income, life_satisfaction, weights = sampling_weight)
# Frequency table
survey_data %>%
frequency(education, weights = sampling_weight)
# Compare groups with t-test
survey_data %>%
t_test(life_satisfaction, group = gender, weights = sampling_weight)
# Detailed SPSS-style output with summary()
survey_data %>%
t_test(life_satisfaction, group = gender, weights = sampling_weight) %>%
summary()
# Scale analysis workflow
reliability(survey_data, trust_government, trust_media, trust_science) %>%
summary() # item statistics, inter-item correlations
survey_data <- survey_data %>%
mutate(m_trust = row_means(., trust_government, trust_media, trust_science))
# Regression
survey_data %>%
linear_regression(life_satisfaction ~ age + income, weights = sampling_weight) %>%
summary() # coefficients, ANOVA table, diagnostics| Category | Functions | Purpose |
|---|---|---|
| Data Import | read_spss(), read_stata(),
read_sas(), read_xlsx(), + 2 more |
Import SPSS, Stata, SAS, and Excel with tagged NA support |
| Data Export | write_spss(), write_stata(),
write_xpt(), write_xlsx() |
Export with full label and missing value roundtripping |
| Label Management | var_label(), val_labels(),
to_label(), set_na(), + 6 more |
Get/set labels, convert formats, declare missing values |
| Data Transformation | rec(), to_dummy(), std(),
center(), find_var() |
Recoding, dummy coding, standardization, centering |
| Descriptive | describe(), frequency(),
crosstab(), multiple_response(),
codebook() |
Summaries, distributions, multiple response sets, data dictionaries |
| Assumption checks | normality_test() |
Kolmogorov-Smirnov (Lilliefors) and Shapiro-Wilk normality tests |
| T-Tests | t_test() |
Mean comparisons (independent and one-sample) |
| ANOVA | oneway_anova(), factorial_anova(),
ancova() |
One-way, multi-factor ANOVA, and ANCOVA with Type III SS |
| Non-parametric | mann_whitney(), kruskal_wallis(),
wilcoxon_test(), friedman_test(),
binomial_test() |
Distribution-free tests |
| Exact tests | chi_square(), fisher_test(),
chisq_gof(), mcnemar_test() |
Categorical associations and exact tests |
| Correlation | pearson_cor(), spearman_rho(),
kendall_tau(), partial_cor() |
Relationships between variables, with and without controls |
| Post-hoc | tukey_test(), scheffe_test(),
levene_test(), dunn_test(),
pairwise_wilcoxon() |
Follow-up analyses (parametric and non-parametric) |
| Scale analysis | reliability(), efa(),
row_means(), row_sums(),
row_count(), pomps() |
Cronbach’s Alpha, factor analysis, index construction |
| Regression | linear_regression(),
logistic_regression(), marginal_effects() |
Linear and logistic models with SPSS-style output, average marginal effects |
| Effect sizes | phi(), cramers_v(),
goodman_gamma() |
Effect size measures for categorical data |
| Weighted stats | w_mean(), w_median(), w_sd(),
+ 8 more |
Individual weighted statistics |
All statistical functions accept survey weights:
# Weighted mean, median, SD
survey_data %>%
w_mean(age, income, weights = sampling_weight)
# Grouped weighted analysis
survey_data %>%
group_by(region) %>%
describe(satisfaction, weights = sampling_weight)Full support for pipes and grouped operations:
survey_data %>%
filter(age >= 18) %>%
group_by(region) %>%
t_test(life_satisfaction, group = gender, weights = sampling_weight)# Factorial ANOVA with Type III SS
survey_data %>%
factorial_anova(dv = income, between = c(gender, education),
weights = sampling_weight)
# ANCOVA with covariate adjustment
survey_data %>%
ancova(dv = income, between = gender, covariate = age,
weights = sampling_weight)# Parametric: ANOVA → Tukey/Scheffe
result <- survey_data %>%
oneway_anova(life_satisfaction, group = education, weights = sampling_weight)
result %>% tukey_test() # Pairwise comparisons
result %>% levene_test() # Variance homogeneity
# Non-parametric: Kruskal-Wallis → Dunn
kw_result <- survey_data %>%
kruskal_wallis(life_satisfaction, group = education)
kw_result %>% dunn_test() # Pairwise Dunn comparisonsEvery analysis function provides two output levels. Typing the result
name prints a compact one-line summary. Calling summary()
produces the full SPSS-style output with all details. You can toggle
individual sections on or off:
# Compact one-line summary (default)
survey_data %>%
t_test(life_satisfaction, group = gender)
# Full detailed output
survey_data %>%
t_test(life_satisfaction, group = gender) %>%
summary()
# Toggle individual sections
survey_data %>%
t_test(life_satisfaction, group = gender) %>%
summary(effect_sizes = FALSE)This works for all analysis functions — t_test(),
oneway_anova(), chi_square(),
pearson_cor(), reliability(),
linear_regression(), and more.
Statistical functions are validated against SPSS v29 within
documented per-tier tolerances, typically across four scenarios:
weighted/unweighted and grouped/ungrouped. Some statistics have no SPSS
equivalent (for example, the weighted variants of the rank-based tests,
which SPSS’s NPAR TESTS does not support) and are covered
by internal regression tests instead. See
vignette("spss-compatibility") for the per-function
validation status. If you’re migrating from SPSS, workflows translate
directly:
SPSS:
WEIGHT BY sampling_weight.
T-TEST GROUPS=gender(1 2)
/VARIABLES=satisfaction.
mariposa:
survey_data %>%
t_test(satisfaction, group = gender, weights = sampling_weight)MIT © 2026 Yannick Diehl