My goal is to successfully run this type of model in R. I know how to set up the dataset and interpret the results using HLM (the program) but I am completely lost when trying to get it into R.

Screenshot of the model is attached.

Right now, for the level 1 dataset I have 4 observations for each subject and for the level 2 dataset I have subject sex as the only variable.

I have a dependent variable that is predicted by two categorical variables (dummy coded - var 1 and var 2) and their interaction (var 3). I'm controlling for subject sex in level 2.

In HLM, what I would do is run the model with var 1 (dummy coded as -0.5 and 0.5) and var 2 (dummy coded as -0.5 and 0.5) and the interaction. If the interaction is significant, I would look for simple effects by recentering var 1 to 0 and 1 and getting a new interaction term. And then running a third model with var 1 as -1 and 0 and the new interaction term.

How would I do this in R?

Specifically...

1) How do I need to construct the datasets to import the data. (Currently have 2 datasets in SPSS for level 1 and level 2).

2) How do I write the syntax for the original model in R?

3) How do I probe the interaction in R? Do I need to pre-create all of the variables I may be interested in or is there a way to do this in R?

The only thing I know to do right now is a model that looks like this:

example <- lmer(DV ~ IV1 + IV2 + IV3 + (1 | GROUP), data = exampledata)

I would greatly appreciate any help!

Thank you!