【问题标题】:How to make confidence interval of linear combination of regression estimator in R?如何在R中制作回归估计量线性组合的置信区间?
【发布时间】:2019-11-12 11:40:27
【问题描述】:

在这个回归中:

我从包 glht 中知道 confit() 可以做每个估计器的置信区间。

但是如何使系数的线性组合的置信区间, 比如R中β3+2*β5的置信区间?

添加了这个

【问题讨论】:

  • 抱歉,我刚刚看到您正在使用 glht。好的,我们可以使用它。下次在你的问题中加入这个?

标签: r statistics regression


【解决方案1】:

您可以使用 car 包中的 linearHypothesis 来做到这一点:

library(car)

dat <- data.frame(
  y = rnorm(100),
  x1 = rnorm(100),
  x2 = rnorm(100)
)

fit <- lm(y ~ x1 + x2, data = dat)

# enter linear hypothesis as a matrix
linearHypothesis(fit, t(c(0,2,2)), 0)
# enter linear hypothesis as a string
linearHypothesis(fit, "2*x1 + 2*x2 = 0")

或者使用multcomp包中的glht,它也提供了线性组合的置信区间:

library(multcomp)

lh <- glht(fit, linfct = t(c(0,2,2)))
confint(lh)
# Linear Hypotheses:
#        Estimate lwr     upr    
# 1 == 0  0.1258  -0.4398  0.6914

【讨论】:

  • 谢谢,但我有样本但不是由data.frame创建的,这意味着回归是'''a = lm(A$y ~ A$x_1 + A$x_2 + A$x_3 + A$x_4 + A$x_5)''',那么为什么 '''linearHypothesis(a, "x_3 + 2*x_5 = 0")''' 会出现“Error in constants(lhs, cnames_symb) :” ?
  • @user265349 无论如何car::linearHypothesis 没有提供置信区间(我误读了你的问题)。使用数据框或矩阵。
  • 好的,你能看看我编辑的图片,告诉我我说的对吗?
  • @user265349 你也可以glht(fit, linfct = "x_3+2*x_5==0")。但这需要有一个数据框,我认为。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-29
  • 1970-01-01
  • 2013-02-17
  • 1970-01-01
  • 2010-11-13
  • 2023-03-26
相关资源
最近更新 更多