# McNemar test Brms package Bayes Factor

I am trying to implement bayesian mc nemar test for proportion equalities in the off - diagonal cells of a 2\times2 table from the paper of Delaportas & Kateri .The data set is from Agresti’s book Categorical Data Analysis chapter 11.But is that correct?


# McNmear test
ratings <- matrix(c(175, 16, 54, 188),
ncol=2,byrow=TRUE,
dimnames = list("2004 Election" = c("Democrat", "Republican"),
"2008 Election" = c("Democrat", "Republican")))
ratings
mcnemar.test(ratings, correct=FALSE)
mcnemar = "data {
int<lower=1> n;
int<lower=0> k;
}
parameters {
real<lower=0,upper=1> theta;
}
model {
theta ~ beta(1, 1);
k ~ binomial(n, theta);
} "
k1 = 16
n1 = 70
data_list1 = list(k = k1,n =n1)
stanmodelH0 = stan_model(model_code = mcnemar, model_name="stanmodel")
stanfitH0   = sampling(stanmodelH0,
data   = data_list1,
iter   = 20000,
warmup = 1000,
chains = 4,
cores  = 4,
seed   = 12345,
print(stanfitH0)
k2 = 54
n2 = 70
data_list2 = list(k = k2,n =n2)
stanmodelH1 = stan_model(model_code = mcnemar, model_name="stanmodel")
stanfitH1   = sampling(stanmodelH1,
data   = data_list2,
iter   = 20000,
warmup = 1000,
chains = 4,
cores  = 4,
seed   = 12345,
print(stanfitH1)

H0 = bridge_sampler(stanfitH0)
H1 = bridge_sampler(stanfitH1)
print(H0)
print(H1)
# compute percentage errors
H0.error <- error_measures(H0)$percentage H1.error <- error_measures(H1)$percentage
print(H0.error)
print(H1.error)
# compute Bayes factor
BF01=bayes_factor(H0,H1,log=TRUE)
print(BF01)



Hi,
this is not really something I understand. Hopefully @Henrik_Singmann is not busy and can help?

I don’t know anything about McNemar’s test, but if you’re going to use bridge_sampling, you need to use target += … statements, not ~ statements.