I have an experiment where I have several subjects that I am analyzing a response for (call this RESPONSE). I am interested in the overall effect of temperature on RESPONSE. RESPONSE is measured once daily for each subject over the course of several weeks. Each subject also belongs to one of two levels of a factor (call this FACTOR). I want to know if the relationship between temperature and RESPONSE differs by factor.
This is longitudinal data measuring a response repeatedly through time on each individual subject. Therefore, I analyze this with a mixed model using lmer in lme4. The model specification looks like this…
Model <- lmer(RESPONSE ~ Temperature + FACTOR + doy + TemperatureFACTOR + FACTORdoy + (1 + doy | subject), data = dat, REML=TRUE)
In this model, doy is the day of the year to account for the fact that the effect is likely to vary through time due to processes occurring within the subject environment. I am interested in the overall effect of temperature on the response. The way this model is set up, I believe it is looking at temperature within each subject only. The image above shows the relationship between temperature and response for one level of FACTOR. You can see that the overall relationship is positive, and a linear regression indicates a highly significant relationship. However, if you look within subjects (graph is color coded by subject, total of four subjects), the relationship is actually slightly negative. It is this slightly negative relationship that the model picks up on, reporting a negative coefficient for this level of FACTOR. I do understand these are not independent observations, so a linear regression is not appropriate. However, it still seems like this should be an overall positive relationship. Is there any way to specify the model so that it accounts for both the within subjects effect of temperature and the between subjects effect of temperature?