1

Using R, I want to compare two coefficients, V1 and V2, from the same regression. I check several posts, but no one answered this issue.

What test can I use to compare slopes from two or more regression models?

Can I compare two regression coefficients

What test can I use to compare slopes from two or more regression models?

Here are some simulated data.

library('MASS')
library(magrittr)

mu <- c(0,0,0)

Sigma <- matrix(.5, nrow=3, ncol=3) + diag(3)*0.3

MyData <- mvrnorm(n=10000, mu=mu, Sigma=Sigma) %>% as.data.frame()

names(MyData) = c('v1', 'v2', 'y')

MyModel = lm(y ~ v1 * v2, data = MyData)

summary(MyModel)

I want to compare the estimate of V1 to the one of V2. So that if V1 and V2 are manipulated, I would like to tell something like "the influence of V1 on Y, is significantly higher than the influence of V2 on Y"

Rtist
  • 243
  • I'm not sure, but it appears you want to do a sensitivity analysis. Maybe partial correlation coefficients would be useful? – Roland Dec 16 '19 at 12:00
  • If your question is about how to do something in R then it is off topic here. But there is clearly a statistical issue here as well. I am voting to leave it open, for now, but others might disagree. If you remove the requirement to use R, then it will clearly be on topic. – Peter Flom Dec 17 '19 at 11:36
  • Do you want to test if $\beta_1=\beta_2$, say (or some inequality). Then test a contrast, see the tag [tag:contrasts] – kjetil b halvorsen Nov 11 '22 at 20:05

1 Answers1

1

It seems you want to compare the coefficients of your model. Call the coefficients in your example $\beta_0, \beta_1,\beta_2, \beta_{12}$ in order, so $\beta_{12}$ is the interaction etc. Comparing coefficients is done using contrasts. Suppose you are interested in the hypothesis $\beta_1=\beta_2$, which we can write as $\beta_2-\beta_1=0$. Define the contrast vector $a=(0, -1, 1, 0)$ then $\beta_2-\beta_1=a^T \beta$ which we can estimate with $ a^T \hat{\beta}$.

If $C$ is the variance matrix of $\hat{\beta}$ then the variance of the contrast is $a^T C a$. Some R code following your coode in the question is

a <- c(0,-1,1,0)
mycontrast <- sum(coef(MyModel)*a) 
se <- sqrt(t(a)*%* vcov(MyModel)*%*a)

test <- mycontrast/se test [,1] [1,] 0.8401622

and then you can use this to construct a test or confidence interval for the contrast. I leave that for you.