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.
According to a comment to this post, BayesFactor::contingencyTableBF() "has to have more than 1 row and more than 1 column". Because the poster mentions: "From the help file, the input table x says: 'an m by n matrix of counts (integers m,n > 1)', so it has to have more than 1 row and more than 1 column". Therefore, BayesFactor::contingencyTableBF() cannot work with what I'm looking for.
Consequently, my questions are:
- Given the example above, what function would allow me to get the Bayesian equivalent of a chi-square goodness of fit in R (i.e., a 1-dimension table)?
- Can you please put in practice the function with the code posted above so it produces a BF result?
P.S.: As suggested in this post, I asked the question in CrossValidated, however, from there I have been sent back here as my query has more to do with a programmation question than a theoretical one.