R - Testing equivalence of coefficients in multivariate multiple regression

核能气质少年 提交于 2021-02-07 09:01:56

问题


I'm trying to conduct a multivariate multiple regression analysis. Fortunately, I've found an excellent page demonstrating how to do so in Stata:

http://www.ats.ucla.edu/stat/stata/dae/mvreg.htm

The issue is that I'm using R, while I've figured out how to do the basics of running a multivariate multiple regression model in R, I'm still not sure how to see if coefficients are different for each dependent variable (as shown in the link). Does anyone know how to compute this analysis in R? Seems like seeing if the same independent variable exerts different effects on each dependent variable is an incredibly useful tool, and I'd love to be able to do it!

UPDATE: Here is a reproducible example of what I've done with my own data thus far:

# data
data(mtcars)

# fitting a multivariate multiple regression where mpg and cyl are predicted by wt and hp
car.mod <- lm(cbind(mpg,cyl) ~ wt + hp,data=mtcars)

# see if there is a multivariate effect of wt and hp
summary(manova(car.mod),test="W")

# Get coefficients for each dependent variable
summary(car.mod)

What I want to know in this example is how I can test the equivalence of "wt" on both "mpg" and "cyl". Apparently, this is possible in Stata using the test command.


回答1:


AFAIK, there is no package that does this, so I would do the manual solution. The manual solution is

z = (b1 - b2) / (b1^2 + b2^2)^(1/2).

Here is the (sloppy) code. There may be a more elegant solution to extract the coefficients and standard errors.

# extract coefficients and SEs
coef_mpg <- coef(summary(car.mod))[[1]]
coef_cyl <- coef(summary(car.mod))[[2]]

# test equality of wt coefficients
z_wt <- (coef_mpg[2, 1] - coef_cyl[2, 1]) / (coef_mpg[2, 2]^2 + coef_cyl[2, 2]^2)^(1/2)
p_wt <- 2*pnorm(-abs(z_wt)) 
p_wt

But I would feel better about a bootstrap solution, which makes fewer assumptions.

require(boot)
b_b <- function(data=mtcars, indices) {
  d <- data[indices, ]
  model_mpg <- lm(mpg ~ wt + hp, data=d)
  model_cyl <- lm(cyl ~ wt + hp, data=d)
  return(coef(model_mpg)["wt"] - coef(model_cyl)["wt"])
}
results <- boot(data=mtcars, statistic=b_b, R=1000)
results


来源:https://stackoverflow.com/questions/40952679/r-testing-equivalence-of-coefficients-in-multivariate-multiple-regression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!