I have a data set with two measured variables (liking and closeness). I asked participants about these two variables across three different domains (friends, coworkers, siblings). If I want to determine if closeness "predicts" (I know I'm stuck with correlational data here) liking, how would I test this in R?

I know how to do a basic lme function, but I'm not quite sure how to add in the random effects of participant.

I've named my variables PID, liking, closeness, and relation. Any help you can provide would be much appreciated!


Welcome to the site, srs6012! I would suggest using the lme4 package for this. You can indeed look at the association between liking and closeness using a random effects/mixed/multilevel model as follows. Make sure that you have coded relation as a factor variable with 3 levels:

m1 <- lmer(liking ~ closeness + relation + (1|PID), data=df)

This model examines the association adjusting for the type of relationship and accounting for the correlation among liking ratings by the same person (the random effect - (1|PID)).

You may want to further test whether the association between closeness and liking is different depending on the relationship. This would require an interaction between closeness and relation:

m2 <- lmer(liking ~ closeness + relation + closeness:relation + (1|PID), data=df)

This will tell you the difference in the closeness-liking association for each of the relation groups. You can use the ggeffects package to graph these associations:

ggpredict(m2, c("closeness", "relation"))%>%plot()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.