I have the following piece of R code (adapted from this stackoverflow thread):
# Set the seed for reproducibility
set.seed(123)
# Generate random data
n <- 490
V1 <- sample(c(1, 2, NA), n, replace = TRUE)
# Create the data frame
df <- data.frame(V1)
# Label the values: 1 = Low, 2 = High
expss::val_lab(df$V1) = expss::num_lab("1 Low
2 High")
# Create a list of tables for each variable to count 1s, 2s, and NAs
count_results <- list(V1 = table(df$V1, useNA = "ifany"))
chisq.test(count_results$V1)
The result of the chi-squared test prints the following:
> chisq.test(count_results$V1)
Chi-squared test for given probabilities
data: count_results$V1
X-squared = 0.2, df = 2, p-value = 0.9048
However, when I try with the BayesFactor's contingencyTableBF() function I get an error:
> BayesFactor::contingencyTableBF(count_results$V1, sampleType = "indepMulti")
Error in BayesFactor::contingencyTableBF(count_results$V1, sampleType = "indepMulti") :
Argument fixedMargin ('rows' or 'cols') required with independent multinomial sampling plan.
My questions:
- Can
BayesFactor::contingencyTableBF()be used in such a case? - If yes, given the example above, what would be the correct syntax?
- If not, given the example above, what function would allow me to get the Bayesian equivalent of a 1-dimension table chi-squared analysis?