如何在R中建立回归估计量线性组合的置信区间?

时间:2019-11-12 11:40:27

标签: r statistics regression

在此回归中:

enter image description here

我从包中知道confit()可以对每个估计量进行置信区间。

但是如何使系数的线性组合的置信区间为 如R3中β3+ 2 *β5的置信区间

添加了此

enter image description here

1 个答案:

答案 0 :(得分:1)

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

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")

或与glht包中的multcomp一起使用,这也为线性组合提供了置信区间:

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
相关问题