I have a model with several main effects and several interactions. I want to avoid any models that would only include the 3 interaction terms. So basically all variations of main effects and main effects with various interactions but not anything with only the interactions.
M1<-glm(R1 ~ scale(X1)+ scale(X2)+ scale(X3)+ scale(X3*X1)+scale(X2*X1)+scale(X2*X3))
I have used 'expression' to subset before for quadratics and it's always worked but for some reason I can't figure out the interactions.
msubset <- expression((`scale(X2)`|!`scale(X2):scale(X1)`)&
(`scale(X3)`|!`scale(X3):scale(X1)`))
#dredge for model selection
M2<-dredge(M1,subset=msubset,rank=AIC)
Any help would be appreciated.
I have never used this functionality in dredge before (it's pretty great to know it exists). I think your issue lies in the use of the
scale()functions in your formula. I don't think this is really necessary. Your model's coefficients are of course influenced by the amplitude of the explanatory variables, but this does not have any effect on whether or not they are determined to help explain the response variable. If possible, I recommend removing these and then the procedure that you wand seems to work indredge():You don't actually have a 3-way interaction in your formula (which would include (
X1:X2:X3, and would be included by the formulaR1 ~ (X1 + X2 + X3)^3.Finally, if the use of
scaleis important to you, and you do not have an issue with computation time, you could always filter your resulting M2 table following your subset criteria afterwards.