I am playing with a toy data where the Simpson's paradox exists for two variables NO2 and temperature:
I am thinking of using lme to detect this, by specifying temperature as a fixed effect and for each subject a random intercept:
summary(lme(NO2~temperature, data=data.frame(data2), random = ~1| subject))
My expectation was that despite the negative correlation at the individual level, the fixed effect of temperature should reflect what is at the population level, i.e. a positive coefficient. However, the results showed the opposite as a negative coefficient for temperature:
My puzzle is:
It seems that the fixed effect estimation result captures the negative correlation between NO2 and temperature within each individual but why?
Is there a method to return both the correlations at the population level as well as the individual level? I tried to add a random slope for each subject like this: