1
$\begingroup$

I'm estimating a basic OLS model, y ~ x, and I want to know the difference in the slope between two groups. Here is a simulated example in R:

set.seed(123)

x <- runif(50, 0, 10)
slope_a <- 1
slope_b <- 3
df <- data.frame(
    x = x,
    y = c(slope_a*x + rnorm(50), slope_b*x + rnorm(50)),
    group = rep(c('a', ''), each = 50)
)

m1 <- lm(y ~ x*group, data = df)
coef(m1)

#> (Intercept)           x      groupa    x:groupa 
#> -0.15881145  3.03108969  0.01645874 -1.99291523 

This correctly recovers the slope parameters for each group, and the intercept is indeed close to 0.

Since the true intercepts are indeed 0, an alternative approach is to compute the slope at each point and regress a model on the slopes as the y variable. In my simulation I am again able to recover the slope parameters:

df$slope <- df$y / df$x
m2 <- lm(slope ~ group, data = df)
coef(m2)

#> (Intercept)      groupa 
#>    3.069613   -2.091512 

My question is when (if ever) is this approach valid? The second approach is essentially forcing the intercept to go through 0, whereas the first is not. So obviously if the true intercept is not 0, then the second approach would be invalid. Am I missing something else important here?

$\endgroup$
1
  • $\begingroup$ Another important issue is that your ratios are now heteroscedastic: their variances depend on x. And because the two models are different, as you note, then how would one determine which is "valid"? At most one can be and assessing its validity would depend on the circumstances. $\endgroup$
    – whuber
    Mar 1 at 17:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.