Skip to content

Instantly share code, notes, and snippets.

View Koalha's full-sized avatar

Konsta Aleksi Happonen Koalha

  • Helsinki
View GitHub Profile
## Bayesian p-values!
library(tidyverse)
library(brms)
library(posterior)
library(tidybayes)
library(glue)
library(ggview)
options(scipen = 999)
set.seed(25)
## Berkson's paradox or collider bias in surveys
library(tidyverse)
library(ggdist)
library(ggview)
library(dagitty)
library(ggdag)
theme_set(theme_minimal(base_family = "Karla"))
## A dag of the scenario
@Koalha
Koalha / fill_by_ci.R
Created January 5, 2025 13:44
Visualize credible intervals using fill aesthetics on a density plot
## You can use the fill aesthetic to indicate indicate uncertainty levels in ggdist geoms!
library(tidyverse)
library(tidybayes)
library(posterior)
library(brms)
library(scico)
library(marginaleffects)
library(ggview)
set.seed(5) #for reproducibility
@Koalha
Koalha / visualize_fuzzy_bars.R
Created January 4, 2025 17:26
Visualize fuzzy stacked bar charts
## Visualize uncertainty in bar charts using fuzzy class boundaries
## as in https://stats.andrewheiss.com/lemon-lucifer/analysis/paper.html
library(tidyverse)
library(tidybayes)
library(ggview)
library(patchwork)
library(glue)
library(scico)
@Koalha
Koalha / cumulative_averages.R
Created December 13, 2024 22:42
Calculating average responses from a cumulative ordinal model.
library(tidyverse)
library(brms)
library(tidybayes)
options(mc.cores = min(parallel::detectCores(),4))
## Simulate data
N <- 1000
dat <- tibble(
y = sample(LETTERS[1:4], replace=TRUE, size = N) |>