Latent interactions and centering

374 views
Skip to first unread message

Tomislav Pavlović

unread,
Nov 1, 2021, 10:52:09 AM11/1/21
to lavaan
Dear everyone, 

I'm having some issues with centering. I'm trying to center the data using indProd() for a second-order interaction and I noticed that the algorithm crashes if I choose anything except mean centering. More specifically, I get this error:

Error in matrix(rep(dat1[, i], length(var3)), ncol = length(var3)) * matrix(rep(dat2[,  : 
  non-numeric argument to binary operator

I double-checked everything and all the introduced variables are numeric. Then I thought the problem was that one of the variables had only a single indicator, so I added some additional indicators, but I still got the same message. Then I changed the order of variables and, in brief, the error occurs whenever I introduce the third variable, regardles which variable it is. So, the algorithm seems to fail when the third variable is introduced. Has anyone else noticed this issue? Or, even better, is there a solution available? These seem to be the code lines of indProd where the error occurs (although this is just my assumption according to the error message):

for (i in 1:length(var1)) {
                for (j in 1:length(var2)) {
                  datProd3way <- data.frame(datProd3way, matrix(rep(dat1[, 
                    i], length(var3)), ncol = length(var3)) * 
                    matrix(rep(dat2[, j], length(var3)), ncol = length(var3)) * 
                    dat3)
                }

Best regards, 

Tomislav Pavlović

unread,
Nov 2, 2021, 1:55:19 PM11/2/21
to lavaan
Dear everyone, 

Several updates: 

I located the problem - the first matrix in the code lines above - matrix(rep(dat1[, i], length(var3)) - was supposed to provide replicates of the columns i from the first data set, but it provided abbreviated output (e.g., numeric, 10) which, of course, R treated as a non-numeric outcome and could not multiply with the second matrix that was numeric. When I replaced matrix() with as.data.frame(), I managed to get some results, which I thought was great. However, reality had different plans. 

While in the manuscript (Testing and Interpreting Latent Variable Interactions Using the semTools Package) it says that we should use only one form of centering at a time, I'm not really sure if doubleMC functions as it should without mean centering. To demonstrate this, I'll calculate interaction scores using four methods (indi is the modified version of indProd, with as.data.frame instead of matrices): firstly, no centering, secondly, mean centering only, thirdly, doubleMC only, fourthly, doubleMC and mean centering. Not sure if it's just me, but the the size of scores when doubleMC is used without mean centering suggests that initial mean centering was not  done. This might be just my interpretation of the code, but the code also suggests that initial mean centering is not done if mean centering is not chosen as T. Does anyone else have similar experience? I do not exclude the possibility that my laptop is trying to sabotage me (it wouldn't be it's first time), so I'd be grateful for any feedback.


centering.png


Finally, when I thought the largest part of the agony way over and tried to conduct my analysis, I found that after double mean centering I still have correlations above acceptable level (my favorite one is .89) between basic dimensions and interactions they include, just as the version with "single" mean centering (correlation matrices are identical).

So... has anyone else experienced this? As I will have to submit a study relatively soon due to some limitations of my contract, I'd really appreciate if I got some feedback on this, which would allow me to reorganize my work in case this is a bit more complex issue than it initially seemed. 

Best regards and thank you in advance,

Alex Schoemann

unread,
Nov 3, 2021, 10:47:29 AM11/3/21
to lavaan
(I accidently sent privately yesterday, reposting for anyone looking in the future)

 Hi,

So if you want to use double mean centering as a way to get product terms you need to set both meanC and doubleMC to TRUE. In the function meanC will center the indicators of the main effect variables, and doubleMC only centers product terms (see the indProd help document https://rdrr.io/cran/semTools/man/indProd.html). The function is built this way for flexibility (if you've already centered your indicators, there's no need to center them again). In our manuscript on the topic we're warning against using both double mean centering and residual centering as methods of creating product indicators.

Assuming you're using the correct product indicators it's still possible to have correlations between lower order variables and the interaction, especially when indicators are not normally distributed.

Alex

Stefanos Mastrotheodoros

unread,
May 18, 2024, 4:08:50 AM5/18/24
to lavaan
Hi all, 

I also encountered a similar problem. There is a sentence in the paper that is somewhat misleading, as it says (page 328) that only one of meanC, residualC, or doubleMC should be set to true, but in my case doubleMC=TRUE alone resulted in an error. Only using both meanC=T, and doubleMC=T worked (and gave different results than only meanC=T and doubleMC=F).

Thanks for your work on this!

Reply all
Reply to author
Forward
0 new messages