Skip to content

Instantly share code, notes, and snippets.

@jirilukavsky
Created June 26, 2024 07:23
Show Gist options
  • Save jirilukavsky/6e77ef38b8bedd80cc6c88faf826388e to your computer and use it in GitHub Desktop.
Save jirilukavsky/6e77ef38b8bedd80cc6c88faf826388e to your computer and use it in GitHub Desktop.
Testing how accurate is parameter recovery for Poisson and binomial models for a large N=1000. Combinations of zeros (0 hits of 0 trials) do not pose a problem.
library(tidyverse)
library(brms)
library(tidybayes)
n <- 1000
lambda <- 2
p <- 0.50
x <- rpois(n, lambda)
y <- rbinom(n, x, p)
d <- tibble(x, y)
mx <- brm(
x ~ 1, data = d, family = poisson
)
summary(mx)
px <- as_draws_df(mx)
px$b_Intercept |> exp() |> mean_hdci()
# y ymin ymax .width .point .interval
# 1 1.982956 1.895036 2.072006 0.95 mean hdci
my <- brm(
y | trials(x) ~ 1, data = d, family = binomial
)
summary(my)
py <- as_draws_df(my)
py$b_Intercept |> inv_logit_scaled() |> mean_hdci()
# y ymin ymax .width .point .interval
# 1 0.4867739 0.4661131 0.5087191 0.95 mean hdci
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment