R - 回归系数的显着性检验

R - significance test of regression coefficient

我有两个假设(A 和 B)
H0_A b1<=0; H1_A: b1 >0
H0_B b2>=0; H1_B: b2 <0

估计系数 b1 和 b2 I 运行 回归 lm(y~x1+x2)

我的问题:如何获得每个系数 (b1, b2) 的 p 值,根据其假设设置,看看我是否可以拒绝原假设?

当我在回归中使用 summary() 函数时,列出了 p 值,但我认为它们只考虑了 beta 不等于零的情况。

非常感谢!!

lm() 函数默认为双侧替代假设检验。作为警示,您应该默认使用双面选择,除非您有强大的理论基础,先验地只对一侧感兴趣。可重现的示例有助于社区更好地为您服务。我在下面推荐了一些代码来帮助提取您的 p 值。根据需要调整分布函数。

# Extracting your p-values (two-sided alternative)

mod <- lm(y ~ x1 + x2, data = ...)
summary(mod)$coefficient[ ,"Pr(>|t|)"]

# Adjusting you're rejection regions

output <- summary( lm(y ~ x1 + x2, data = ...) )

t <- coef(output)[ ,3]   # extracting the t-values
df <- output$df          # extracting the degrees of freedom
pt(t, df, lower = ...)   # lower = TRUE/FALSE (b < 0 or b > 0, respectively)