Search code examples
rlme4interactionordinal

LMER Factor vs numeric Interaction


I am attempting to use lmer to model my data.

My data has 2 independent variables and a dependent variable.

The first is "Morph" and has values "Identical", "Near", "Far".
The second is "Response" which can be "Old" or "New".
The dependent variable is "Fix_Count".

So here is a sample dataframe and what I currently have for running the linear model.

Subject <- c(rep(1, times = 6), rep(2, times = 6))
 q <- c("Identical", "Near", "Far")
 Morph <- c(rep(q, times = 4))
 t <- c(rep("old", times = 3),rep("new", times=3))
 Response <- c(rep(t, times = 2))
 Fix_Count <- sample(1:9, 12, replace = T)
 df.main <- data.frame(Subject,Morph, Response, Fix_Count, stringsAsFactors = T)
df.main$Subject <- as.factor(df.main$Subject)

 res = lmer(Fix_Count ~ (Morph * Response) + (1|Subject), data=df.main)
 summary(res)

And the output looks like this: enter image description here

The issue is I do not want it to do combination but an overall interaction of Morph:Response.

I can get it to do this by converting Morph to numeric instead of factor. However I'm not sure conceptually that makes sense as the values don't properly represent 1,2,3 but low-mid-high (ordered but qualitative).

So: 1. Is it possible to run lmer to get interaction effects between 2 factor variables?
2. Or do you think numeric is a fine way to class "Identica", "Near", "Far"?
3. I have tried setting contrasts to see if that can help, but sometimes I get an error and other times it seems like nothing is changed. If contrasts would help, could you explain how I would implement this?

Thank you so much for any help you can offer. I have also posted this question to stack exchange as I am unsure if this is a coding issue or a stats issue. However I can remove it from the less relevant forum once I know.

Best, Kirk


Solution

  • Two problems I see. First, you should be using a factor variable for Subject. It's clearly not a continuous or integer variable. And to (possibly) address part of your question, there is an interaction function designed to work with regression formulas. I'm pretty sure that the formula interface will interpret the "*" operator that you used as a call to interaction, but the labeling of the output may be different and perhaps more to your liking. I get the same number of coefficients with:

    res = lmer(Fix_Count ~ interaction(Morph , Response) + (1|Subject), data=df.main)
    

    But that's not an improvement. However, they differ from the model created with Morph*Response. Probably there is a different set of contrast options.

    The way to get an overall statistical test of the interaction is to compare nested models:

    res_simple = lmer(Fix_Count ~ Morph + Response + (1|Subject), data=df.main)
    

    And then do an anova for the model comparison:

    anova(res,res_simple)
    refitting model(s) with ML (instead of REML)
    Data: df.main
    Models:
    res_simple: Fix_Count ~ Morph + Response + (1 | Subject)
    res: Fix_Count ~ interaction(Morph, Response) + (1 | factor(Subject))
               Df    AIC    BIC  logLik deviance  Chisq Chi Df Pr(>Chisq)
    res_simple  6 50.920 53.830 -19.460   38.920                         
    res         8 54.582 58.461 -19.291   38.582 0.3381      2     0.8445
    

    My opinion is that it is sufficiently close to the boundary for stats vs coding that it could have been acceptable on either forum. (You are not supposed to cross post, however.) If you are satisfied with a coding answer then we are done. If you need help with understanding model comparison, then you may need to edit your CV.com's question to request a more theory-based answer than mine. (I checked to make sure the anova results are the same regardless of whether you use the interaction function or the "*" operator.)