3
$\begingroup$

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)

enter image description here

There are two ways to model this relationship. The first would be to model y as an interaction between x and 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 y / 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:

  1. 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).

  2. 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?

  3. How would you defend either approach over the other to a "non-statistician"?

$\endgroup$
4
+50
$\begingroup$

Ratios are often poorly behaved and should be avoided in general.

Question 3. Consider the 2 leftmost points on your graph, which I read to have an x value of 0.1 for both and y values of +1 and -2. They are close on the plot, but the y/x ratios are +10 and -20, respectively. That discrepancy in ratio between 2 close points shouldn't feel right even to a non-statistician. Even most non-statisticians remember that you "shouldn't divide by zero," yet that (or something close to that) is what taking a ratio often entails.

Question 1. This freely available paper by Douglas Curran-Everett in Advances in Physiology Education goes into the problems with statistics on ratios. It is full of examples with R code. Ratios can be meaningful if there is a strict proportionality between y and x, and sometimes ratios have useful heuristic properties, but as your example shows once you have errors around the proportionality you can get into trouble, particularly with data close to zero. As Curran-Everett demonstrates, regression models win over ratios.

If you have strictly positive data and are interested in ratios, regression based on logarithms of values may be useful, as $\log(y/x)=\log(y)-\log(x)$. This is particularly appropriate if measurement errors are proportional to the magnitudes of the values, as errors in the log-transformed scale will be relatively independent of values so that standard statistical tests can be applied in the transformed scale.

Question 2. The answer depends heavily on the nature of your data. There is a danger that your analysis based on ratios is coming up with spurious results. There is also the possibility that your data don't have the nice linear relations of your posted simplistic example, so sometimes the ratios correct for some underlying nonlinearily. Looking carefully at many plots is the best way to try to figure out what's going on. If you have strictly positive data, consider working in the log scales as suggested above.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.