【问题标题】:What package in R is used to calculate non-zero null hypothesis p-values on linear models?R中的哪个包用于计算线性模型上的非零零假设p值?
【发布时间】:2021-03-18 07:53:16
【问题描述】:

标准summary(lm(Height~Weight)) 将输出假设检验 H0: Beta1=0 的结果,但如果我有兴趣检验假设 H0: B1=1 是否有可以产生该 p 值的包?我知道我可以手动计算它,我知道我可以“翻转置信区间”进行双尾检验(通过查看 95% confint 是否包含兴趣点来测试 95% 的假设),但我正在寻找为模拟研究生成 p 值的简单方法。

【问题讨论】:

  • 最好将此问题表述为“我如何……?”而不是“我使用什么包......?”;包推荐问题在技术上对于 StackOverflow 来说是题外话(尽管我之前曾争论过这对 R 没有多大意义......)
  • this 回答你的问题了吗?

标签: r linear-regression lm


【解决方案1】:

您可以使用 car 包中的 linearHypothesis,例如:

library(car)
fit = lm(Petal.Width ~ Petal.Length,data=iris)

fit

Call:
lm(formula = Petal.Width ~ Petal.Length, data = iris)

Coefficients:
 (Intercept)  Petal.Length  
     -0.3631        0.4158  

linearHypothesis(fit,"Petal.Length=0.4")
Linear hypothesis test

Hypothesis:
Petal.Length = 0.4

Model 1: restricted model
Model 2: Petal.Width ~ Petal.Length

  Res.Df    RSS Df Sum of Sq      F Pr(>F)
1    149 6.4254                           
2    148 6.3101  1   0.11526 2.7034 0.1023

还有一个 article 关于这个包的细节。

【讨论】:

    【解决方案2】:

    我不知道有什么包可以做到这一点,但你可以通过使用偏移量来检验这个假设:

    ## specify null-model parameters
    null_int <- 0; null_slope <- 1
    ## base model
    m0 <- lm(mpg ~ disp, data=mtcars)
    ## include offset as null model
    m1 <- update(m0, . ~ . + offset(null_int + null_slope*disp))
    

    比较结果:

    cbind(base=coef(m0),offset=coef(m1))
                      base    offset
    (Intercept) 29.59985476 29.599855
    disp        -0.04121512 -1.041215
    

    您可以看到估计的斜率现在降低了 1 个单位(因为它与斜率 = 1 的空模型相关)。汇总值、标准误、p 值等都会进行适当调整。

    【讨论】:

      猜你喜欢
      • 2011-12-28
      • 2017-07-20
      • 2022-11-03
      • 2020-06-01
      • 2010-10-09
      • 1970-01-01
      • 2017-05-26
      • 1970-01-01
      相关资源
      最近更新 更多