【问题标题】:In R, comparing two regression coefficients from the same model在 R 中,比较来自同一模型的两个回归系数
【发布时间】:2019-12-17 19:00:34
【问题描述】:

使用 R,我想对来自同一回归的两个系数进行统计比较。在 Stata 软件中,有测试 B1 = B2。 R中的等价物是什么?我检查了几篇帖子,但没有人回答这个问题。

https://stats.stackexchange.com/questions/33013/what-test-can-i-use-to-compare-slopes-from-two-or-more-regression-models

SPSS: Comparing regression coefficient from multiple models

Comparing regression models in R

这是一些模拟数据。

library('MASS')

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)

我想将 V1 的估计值与 V2 的估计值进行比较。因此,如果 V1 和 V2 被操纵,我想说“V1 对 Y 的影响,明显高于 V2 对 Y 的影响”

【问题讨论】:

标签: r regression anova


【解决方案1】:

你可以试试multcomp,所以如果你看看你的模型的系数:

coefficients(MyModel)
(Intercept)           v1           v2        v1:v2 
 0.006961219  0.373547048  0.394760005 -0.012167754 

您想找出第 2 项和第 3 项之间的差异,因此您的对比矩阵是:

# yes it looks a bit weird at first
ctr = rbind("v1-v2"=c(0,1,-1,0))

我们可以使用glht

summary(glht(MyModel,ctr))

     Simultaneous Tests for General Linear Hypotheses

Fit: lm(formula = y ~ v1 * v2, data = MyData)

Linear Hypotheses:
           Estimate Std. Error t value Pr(>|t|)
v1-v2 == 0 -0.02121    0.01640  -1.294    0.196
(Adjusted p values reported -- single-step method)

这适用于大多数通用线性模型。在您的摘要函数中,您可以根据效果/标准误差获得每个术语的重要性。 glht 函数做了类似的事情。我能想到的逻辑回归的一个例外是当你有complete separation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-13
    • 2012-09-16
    • 2016-02-27
    • 2013-11-28
    • 1970-01-01
    • 2023-04-11
    相关资源
    最近更新 更多