Skip to content

Instantly share code, notes, and snippets.

View adrianolszewski's full-sized avatar

Adrian Olszewski adrianolszewski

View GitHub Profile
@adrianolszewski
adrianolszewski / likert_ggplot2.md
Created October 4, 2025 02:55
Examples of Likert diverging (pyramid) plot with ggplot2

Likert plot - version 1, the middle "2+ normal" option is the neutral one, not counted for %

Packages:

library(ggstats)
library(likert)
library(ggplot2)
library(patchwork)

The main plot - uses the ggstats package and the Likert_CFB_formed dataset.

@adrianolszewski
adrianolszewski / linkedin_30_05_2025_anova_residuals.md
Created May 30, 2025 15:25
ANOVA: distribution of residuals = mixture of distribtions of per-group mean-centered raw data
library(dplyr)
library(ggplot2)
library(ggh4x)
library(geomtextpath)

set.seed(12345)

N <- 150
data <- data.frame(response = c(rnorm(N, mean = 1, sd = 1),
@adrianolszewski
adrianolszewski / Olszewski_quartet.md
Last active December 10, 2024 03:02
My own version of the Anscombe's quartet :-)

Olszewski's vs. Anscombe's quartet

You probably heard about the Anscombe's quartet. It's almost a textbook justification for looking at the data first and not trusting solely descriptive statistics!

I decided to make my own, Olszewski's quartet! It shows 4 faces in different moods. The mean and variance of the Y coordinate is exactly (NOT approximately!) the same for all 4 faces. Also, the Pearson's correlation is almost 0.

93b1d1f6-8710-485e-a751-0d7cb45b1cae

How did I make it?

@adrianolszewski
adrianolszewski / logistic_regression_testing_hypotheses.md
Last active February 18, 2024 23:38
Logistic regression is often used for testing hypotheses, replacing a variety of common classic tests

Despite the widespread and nonsensical claim, that "logistic regression is not a regression", it constitutes one of the key regression and hypothesis testing tools used in the experimental research (like clinical trials).

Let me show you how the logistic regression (with a few extensions) can be used to test hypotheses about fractions (%) of successes, repacling the classic "test for proportions". Namely, it can replicate the results of:

  1. the Wald's (normal approximation) z test for 2 proportions with non-pooled standard errors (common in clinical trials) via LS-means on the prediction scale or AME (average marginal effect)
  2. the Rao's score (normal appr.) z test for 2 proportions with pooled standard errors (just what the prop.test() does in R)
  3. the z test for multiple (2+) proportions
  4. ANOVA-like (joint) test for multiple caterogical predictors (n-way ANOVA). Also (n-way) ANCOVA if you employ numerical covariates.
  5. [the **Cochran-Mantel-Haenszel
@adrianolszewski
adrianolszewski / quantreg_mww.r
Last active August 4, 2026 10:50
Mann-Whitney (Wilcoxon) and Kruskal-Wallis FAIL to compare medians in general. Quantile regression should be used to compare medians instead
Despite a common claim that Mann-Whitney (Wilcoxon), Kruskal-Wallis, Fligner-Poicello and other rank-based tests compare medians,
**this is a widespread misconception when considered in general**, i.e. unless strong IID condition is met, resulting in the location-shift case, consistent with the proportional-odds model.
This misconception has been spread so widely, so many textbooks, free and paid courses, even academic lecturers repeat it.
This is by-definition (by construction) a test of stochastic equivalence vs superiority, i.e. whether P(B>A) + 0.5*P(B=A) = 0.5.
Such superiority may occur for a difference in any properties of the compared samples:
- **locations** (means, medians, Hodges-Lehman 2-sample pseudo-median and other measures),
- **dispersions** (variances, general scale parameter, range),
- **shapes** (skewness, kurtosis)