Morning all,
I have two custom functions that I wrote this morning to make the process of building tables for my Bayes factor tests easier, but I could use help tweaking the code to generalize them. Specifically, what I want to do is change their input to somehow allow for any number of comparison tests, instead of the temporary two I have now.
In the paper I'm currently writing I compared three models, but obviously the number of models will change from paper to paper. So instead of changing the functions for every paper, I would like a way to make the code adaptable, and apply my first function to "model i" in the list of models I give it, and then use the section function to glue all given models together. Not sure how to do this though...I assume it involves a for loop?
If anyone has any tips on how to tweak the function to handle a list of inputted models I'd be very grateful. Here is a picture of the (unfinishedflextable in Word to show you what I'm after:
# functions
BF_table=function(BF_output){
BF_output=BF_output
BF_output$BF=round(BF_output$BF,2)
BF_output=add_row(BF_output,Model="Test X", .before=1)
BF_output$Evidence=c("")
return(BF_output)
}
glue_BFs=function(test_1, test_2){
test_1=BF_table(test_1)
test_2=BF_table(test_2)
new_table=rbind(test_1,test_2)
return(new_table)
}
# original code for creating the tables without the above functions
#Bayes factors
#Test 1
BFtesttable=ModelsBF
BFtesttable$BF=round(BFtesttable$BF,2)
BFtesttable=add_row(BFtesttable, Model="Test 1", .before = 1)
BFtesttable$Evidence=c("")
#test 2
BFtesttable2=ModelsBF2
BFtesttable2$BF=round(BFtesttable2$BF,2)
BFtesttable2=add_row(BFtesttable2, Model="Test 2", .before = 1)
BFtesttable2$Evidence=c("")
#test 3
BFtesttable3=ModelsBF3
BFtesttable3$BF=round(BFtesttable3$BF,2)
BFtesttable3=add_row(BFtesttable3, Model="Test 3", .before = 1)
BFtesttable3$Evidence=c("")
#Bind together
Bayesfactors=rbind(BFtesttable,BFtesttable2, BFtesttable3)
rm(BFtesttable,BFtesttable2,BFtesttable3)