0

I am new to R and am looking for some help on automatically producing a series of contingencyTableBF objects for tables created from my data. I want to use such a contingency table as it generates Bayes Factor values for each table. I have searched on the internet without success and on stackoverflow, where I found the below guidance, but I don't know how to convert it to my purpose:

R: Count or contingency tables produced using a loop

In terms of the contingencyTableBF, I wish to use the following parameters related to sampleType and fixedMargin, with the C_BA object being the name of a table I created:

contingencyTableBF(C_BA, sampleType = "indepMulti", fixedMargin = "cols")

I have used the code below to create a table, and ideally would also like to automate this process for all tables. The purpose of each table is to demonstrate the totals between the Dependent Variable and any given Predictor Variable. With the filter function, I have used == and != instructions to generate the four values in the matrix. I wish to generate separate tables to indicate the totals for the Dependent Variable and each Predictor Variable in my data

TRG <- filter(dataset, DependentVariable == 1 & PredictorVariable == 1)
C_BA <- matrix(c(554, 1631, 336, 2078), ncol = 2, byrow = T)
colnames(C_BA) <- c("DependentVariable", "NotDependentVariable")
rownames(C_BA) <- c("PredictorVariable", "NotPredictorVariable")
C_BA <- as.table(C_BA)
C_BA

Any help would be great, thanks very much

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
  • 1
    I really don't quite understand your question. if you do ```with(dataset,table(DependentVariable,PredictorVariable))``` , you get the contingency table. what loop or iteration are you referring to – StupidWolf Sep 04 '20 at 18:57
  • Thanks for the feedback. I'll try to clarify things. I am trying to create two loops. The first would automatically create separate contingency tables for all predictor variables given the same dependent variable. The second loop would then automatically apply the contingencyTableBF function to each newly created contingency table. Maybe the two loops could be combined? Thanks again. – Nicholas Bradley Sep 05 '20 at 11:18
  • A reproducible example with some data would help us answer your question. – DaveArmstrong Sep 06 '20 at 11:26

0 Answers0