Currently I have the following brm model with a continous outcome variable y and a mixture of continuous and ordinal predictors:
original_model = brm(y ~ (var1 + var2)*(var3)+(var1+var2|ParticipantID), data=df,family='gaussian',iter=1000,cores=4,chains=4,control=list(adapt_delta=0.9))
I am now trying to make the formula dynamic so that at every iteration in a loop a different predictor can be left out. The purpose of this is for power calculations; for every predictor, I want to calculate bayes_R2 for the model with the predictor of interest and again for the model without the predictor of interest.
The difficulty is that sometimes I want to dynamically omit an interaction term. For example, in the model above I may want to include interaction (var1 x var3) but omit (var2 x var3) from the model. So far I have come up with the following solution:
# First I construct two strings that describe all the main and # interaction terms I want in each version of the model: formula_withKeyVar <- as.formula("y ~ var1 + var2 + var3 + (var1*var3) + (var2*var3) + (var1 + var2 | ParticipantID") formula_withoutKeyVar <- as.formula("y ~ var1 + var2 + var3 + (var1*var3) + (var1 + var2 | ParticipantID") # omitting (var2*var3) # Then I plug each formula into a model and calculate bayes_R2 for each: model1 = brm(formula = formula_withKeyVar, data=df,family='gaussian',iter=1000, chains=4,cores=4,control=list(adapt_delta=0.9)) model2 = brm(formula=formula_withoutKeyVar,data=df,family='gaussian', iter=1000,chains=4,cores=4,control=list(adapt_delta=0.9))
So my question is: is the above method an appropriate way to make a brm formula dynamic in order to omit interaction terms? I am concerned because model1 takes a lot longer to run than original_model, and the power calculation seems erroneous, so I wonder if my approach is achieving what it’s intended to achieve. Thanks, I appreciate any advice.