I know a little about Bayesian models of Fisher’s exact test, from the rate of left-handedness different between the male and female groups.
library(tidyverse)
library(rstan)
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())
tb <- tibble::tribble(
~sex, ~left_handed, ~right_handed,
"male", 9L, 43L,
"female", 4L, 44L
)
stan_program <- "
data {
int<lower=1> event_1;
int<lower=1> event_2;
int<lower=1> n_1;
int<lower=1> n_2;
}
parameters {
real<lower=0,upper=1> p_1;
real<lower=0,upper=1> p_2;
}
model {
event_1 ~ binomial(n_1, p_1);
event_2 ~ binomial(n_2, p_2);
p_1 ~ beta(5, 40);
p_2 ~ beta(5, 40);
}
generated quantities {
real diff = p_1 - p_2;
}
"
stan_data <- list(
n_1 = 52, # male
event_1 = 9, # left-handed male
n_2 = 48, # female
event_2 = 4 # left-handed female
)
stan_fit <- stan(model_code = stan_program, data = stan_data)
But I have a new @mcmc_stan questions for chi-square test, such as the case below
library(tidyverse)
load(url("https://bit.ly/2E65g15"))
gss %>%
select(party, NASA) %>%
ggplot(aes(x = party, fill = NASA)) +
geom_bar()
Classical approach
chisq.test(gss$party, gss$NASA)
What is the bayesian counterpart to the chi-square test ?
Can you give me some advice?