测试R中多个系数的相等性 [英] Testing the equality of multiple coefficients in R

查看:104
本文介绍了测试R中多个系数的相等性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下模型:

y = b1_group1*X1 + b1_group2*X1 + b2_group1*X2 + b2_group2*X2 + ... +
    b10_group1*X10 + b10_group2*X10

可以很容易地在R中进行如下制作:

Easily made in R as follows:

OLS <- lm(Y ~ t1:Group + t2:Group + t3:Group + t4:Group + t5:Group + t6:Group +
          t7:Group + t8:Group + t9:Group + t10:Group,weights = weight, Alldata)

在STATA中,我现在可以进行以下测试:

In STATA, I can now do the following test:

test (b1_group1=b1_group2) (b2_group1=b2_group2) (b3_group1=b3_group2)

  • b1_group1-b1_group2 = 0
  • b2_group1-b2_group2 = 0
  • b3_group1-b3_group2 = 0
  • 通过F检验,我告诉我X1,X2和X3的系数组在1组和2组之间是否共同不同.

    Which tells me whether the group of coefficents from X1, X2 and X3 are jointly different between Group 1 and Group 2 by means of an F test.

    有人可以告诉我如何在R中执行此操作吗?谢谢!

    推荐答案

    看这个例子:

    library(car)
    
    mod <- lm(mpg ~ disp + hp + drat*wt, mtcars)
    linearHypothesis(mod, c("disp = hp", "disp = drat", "disp = drat:wt" ))
    Linear hypothesis test
    
    Hypothesis:
    disp - hp = 0
    disp - drat = 0
    disp - drat:wt = 0
    
    Model 1: restricted model
    Model 2: mpg ~ disp + hp + drat * wt
    
      Res.Df    RSS Df Sum of Sq      F  Pr(>F)  
    1     29 211.80                              
    2     26 164.67  3    47.129 2.4804 0.08337 .
    ---
    Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
    

    有关指定测试的各种其他方式,请参见?linearHypothesis.

    See ?linearHypothesis for a variety of other ways to specify the test.

    替代:

    以上内容为您提供了一种进行假设检验的快速简便的方法.对假设检验的代数有深入了解的用户可能会发现以下方法更方便,至少对于检验的简单版本而言.假设我们要测试cylcarb的系数是否相同.

    The above shows you a quick and easy way to carry out hypothesis tests. Users with a solid understanding of the algebra of hypothesis tests may find the following approach more convenient, at least for simple versions of the test. Let's say we want to test whether or not the coefficients on cyl and carb are identical.

    mod <- lm(mpg ~ disp + hp + cyl + carb, mtcars)
    

    以下测试是等效的:

    测试一:

    linearHypothesis(mod, c("cyl = carb" ))
    
    Linear hypothesis test
    Hypothesis:
    cyl - carb = 0
    Model 1: restricted model
    Model 2: mpg ~ disp + hp + cyl + carb
      Res.Df    RSS Df Sum of Sq      F Pr(>F)
    1     28 238.83                           
    2     27 238.71  1   0.12128 0.0137 0.9076
    

    测试二:

    rmod<- lm(mpg ~ disp + hp + I(cyl + carb), mtcars)
    anova(mod, rmod)
    
    Analysis of Variance Table
    Model 1: mpg ~ disp + hp + cyl + carb
    Model 2: mpg ~ disp + hp + I(cyl + carb)
      Res.Df    RSS Df Sum of Sq      F Pr(>F)
    1     27 238.71                           
    2     28 238.83 -1  -0.12128 0.0137 0.9076
    

    这篇关于测试R中多个系数的相等性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆