I have some data where the relationship between x and y is modified based on which category an observation belongs to. Here are some sample data, as well as a plot of x vs. y, generated in R:
x<- seq(0.1,10,by=0.1) y<- c(x*1.5 + rnorm(100),x*3 + rnorm(100)) x<- c(x,x) g<- c(rep('A',100), rep('B',100)) d<-data.frame(y,x,g) plot(y~x, data=d, pch=16)
There are two ways to model this relationship. The first would be to model
y as an interaction between
g, the group variable, like this:
mod<- lm(y~x*g,data=d) summary(mod) Call: lm(formula = y ~ x * g) Residuals: Min 1Q Median 3Q Max -2.37039 -0.71772 -0.01103 0.75209 2.34039 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.05885 0.21999 -0.268 0.789 x 1.51336 0.03782 40.015 <2e-16 *** gB -0.05651 0.31111 -0.182 0.856 x:gB 1.49109 0.05349 27.878 <2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 1.092 on 196 degrees of freedom Multiple R-squared: 0.9812, Adjusted R-squared: 0.981 F-statistic: 3418 on 3 and 196 DF, p-value: < 2.2e-16
Everything here is happy and nice. True relationships are captured nicely by the model. In principle however, I should also be able to describe this relationship by modeling the ratio of
x as a function of the main effect of
g, group. Here is what happens:
d$y.r<- y/x summary(lm(y.r~g,data=d)) Call: lm(formula = y.r ~ g, data = d) Residuals: Min 1Q Median 3Q Max -21.0816 -0.1411 0.1256 0.2960 5.2378 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.5383 0.1676 9.180 < 2e-16 *** gB 1.1939 0.2370 5.038 1.06e-06 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 1.676 on 198 degrees of freedom Multiple R-squared: 0.1136, Adjusted R-squared: 0.1091 F-statistic: 25.38 on 1 and 198 DF, p-value: 1.058e-06
The model detects the effect, however the effect size is off, the error is much larger and the r2 is much lower. So, my questions are:
When is it appropriate to model the ratio of two values as a main effect of a predictor, rather than predicting one of the variables as the interaction between the other and the categorical predictor? (bonus for specific examples).
This is an overly simplistic example of a real analysis problem I am dealing with. I am finding that modeling ratios works better than the interaction sometimes, but not others. "Better" meaning I can detect an effect with the ratio but not the interaction in some data sets, but in others the opposite is true. What may cause this to be the case?
How would you defend either approach over the other to a "non-statistician"?