R
Code examples • Assumptions • ReportingSPSS
Menus • Outputs • ReportingMean Comparisons & ANOVA (R)
Independent-samples t-test
- When to use: DV numeric, one between-subjects IV with two groups.
- Assumptions: independence; ~normal DV within each group; variance homogeneity (Levene). If variances unequal, use Welch.
- R code:
# Welch t-test (default in t.test when var.equal = FALSE) t.test(y ~ group, data = d, var.equal = FALSE) # Check assumptions car::leveneTest(y ~ group, data = d) # homogeneity shapiro.test(d$y[d$group=="A"]) # normality by group
- Report: t(df) = value, p = value, Cohen's d, 95% CI.
- Alternatives: Mann–Whitney U if non-normal/outliers and ordinal/continuous DV.
One-way ANOVA
- When to use: DV numeric, one between-subjects IV with ≥3 groups.
- Assumptions: independence; normality; homogeneity (Levene). Use Welch ANOVA if variances unequal.
- R code:
aov1 <- aov(y ~ group, data=d) summary(aov1) car::leveneTest(y ~ group, data=d) # Welch ANOVA oneway.test(y ~ group, data=d, var.equal=FALSE) # Post-hoc (Tukey for homoscedastic) TukeyHSD(aov1) # Games-Howell for heteroscedastic userfriendlyscience::oneway(as.factor(group), y, posthoc = "games-howell", data=d)
- Report: F(df1, df2) = value, p, η2 or partial η2, post-hoc MD with CI.
- Alternatives: Kruskal–Wallis for nonparametric.
Repeated-measures ANOVA
- When to use: DV numeric measured on the same subjects across ≥2 levels (within-subjects factor).
- Assumptions: sphericity (Mauchly); normality of differences.
- R code:
# Using afex + emmeans aov_rm <- afex::aov_ez(id = "id", dv = "y", within = "time", data=d) summary(aov_rm) # Sphericity correction is provided; follow-ups aemm <- emmeans::emmeans(aov_rm, ~ time) emmeans::pairs(aemm, adjust="bonferroni")
- Report: Greenhouse–Geisser-corrected F, p, partial η2, post-hocs with adjustment.
- Alternatives: Friedman test (nonparametric).
Associations & Regression (R)
Pearson & Spearman Correlation
- When to use: two numeric variables (Pearson); monotonic but non-normal or ordinal (Spearman).
- Assumptions: linearity, normality (Pearson); monotonicity (Spearman).
- R code:
cor.test(d$x, d$y, method = "pearson") cor.test(d$x, d$y, method = "spearman") # Diagnostic car::qqPlot(d$y); graphics::pairs(d[c("x","y")]) - Report: r(df) = value, p, 95% CI.
Linear Regression
- When to use: DV numeric, IVs numeric/categorical.
- Assumptions: linearity, independence, homoscedasticity, normal residuals, no multicollinearity.
- R code:
m <- lm(y ~ x1 + x2 + factor(group), data=d) summary(m) car::vif(m) # multicollinearity plot(m) # residual diagnostics
- Report: F, R2, coefficients (β, SE, t, p), CI.
Logistic Regression
- When to use: DV binary; IVs numeric/categorical.
- Assumptions: independent observations; linearity of logit for numeric IVs; no severe multicollinearity.
- R code:
glm1 <- glm(y_bin ~ x1 + x2 + factor(group), data=d, family=binomial) summary(glm1) # Odds ratios exp(cbind(OR = coef(glm1), confint(glm1)))
- Report: OR with 95% CI, Wald z, p, model fit (AIC), pseudo-R2.
Nonparametric & Categorical (R)
Mann–Whitney U (Wilcoxon rank-sum)
- When to use: DV ordinal/continuous non-normal; two independent groups.
- R code:
wilcox.test(y ~ group, data=d, exact=FALSE) # Effect size r effsize::rank_biserial(y ~ group, data=d)
Wilcoxon Signed-Rank
- When to use: two related measurements.
- R code:
wilcox.test(d$y1, d$y2, paired=TRUE, exact=FALSE)
Chi-square Tests
- When to use: association between two categorical variables; goodness-of-fit to expected counts.
- R code:
tab <- table(d$x_cat, d$y_cat) chisq.test(tab) # independence fisher.test(tab) # small expected counts
- Report: χ²(df) = value, p, effect size (Cramér's V).
Mean Comparisons & ANOVA (SPSS)
Independent-samples t-test
- When to use: DV scale, one between-subjects IV with two groups.
- Run: Analyze → Compare Means → Independent-Samples T Test. Set DV; set grouping variable and define groups.
- Check: Analyze → Descriptive Statistics → Explore (normality, plots). Levene's Test in t-test output.
- Read: “Independent Samples Test” table → Levene's Test row, then the appropriate t row (Equal variances assumed/not assumed).
- Report: t(df) = value, p, Cohen's d, 95% CI.
- Alternative: Mann–Whitney U: Analyze → Nonparametric Tests → Legacy Dialogs → 2 Independent Samples.
One-way ANOVA
- Run: Analyze → Compare Means → One-Way ANOVA; Options → Homogeneity of variance; Post Hoc → Tukey (equal variances) or Games–Howell (unequal).
- Read: “Test of Homogeneity of Variances”; “ANOVA”; “Multiple Comparisons”.
- Report: F(df1, df2), p, effect size (η2/partial η2), post-hoc MD & CI.
Repeated-measures ANOVA
- Run: Analyze → General Linear Model → Repeated Measures; define within-factor; Add; Specify; Options → Estimates of effect size, Mauchly's test; EM Means → pairwise comparisons.
- Read: “Mauchly's Test of Sphericity”; “Tests of Within-Subjects Effects”; “Pairwise Comparisons”.
- Report: GG-corrected F, p, partial η2, adjusted pairwise comparisons.
Associations & Regression (SPSS)
Pearson & Spearman Correlation
- Run: Analyze → Correlate → Bivariate; select Pearson or Spearman.
- Read: “Correlations” table: correlation coefficient, p, N.
Linear Regression
- Run: Analyze → Regression → Linear; Statistics → Estimates, Confidence intervals, Collinearity diagnostics.
- Read: “Model Summary” (R2), “ANOVA”, “Coefficients”.
Binary Logistic Regression
- Run: Analyze → Regression → Binary Logistic.
- Read: “Variables in the Equation” (B, Wald, Exp(B), CI), “Model Summary”.
Nonparametric & Categorical (SPSS)
Mann–Whitney U
- Run: Analyze → Nonparametric Tests → Legacy Dialogs → 2 Independent Samples → Mann–Whitney U.
- Read: “Test Statistics”.
Wilcoxon Signed-Rank
- Run: Analyze → Nonparametric Tests → Legacy Dialogs → 2 Related Samples → Wilcoxon.
Chi-square (Independence)
- Run: Analyze → Descriptive Statistics → Crosstabs → Statistics → Chi-square; Cells → expected counts.
- Read: “Chi-Square Tests”; “Symmetric Measures” for Cramér's V.