简体   繁体   English

如何在R中制作回归估计器线性组合的置信区间?

[英]How to make confidence interval of linear combination of regression estimator in R?

In this regression:在这个回归中:

在此处输入图像描述

I know confit() from the package glht can do confidence interval of every estimator.我知道 package glht 中的confit()可以对每个估计器进行置信区间。

But how to make confidence interval of a linear combination of coefficients, such as confidence interval of β3+2*β5 in R?但是如何制作系数线性组合的置信区间,例如R中β3+2*β5的置信区间?

Added this添加了这个

在此处输入图像描述

You can do that with linearHypothesis in the car package:您可以在car package 中使用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")

Or with glht in the multcomp package, which also provides a confidence interval for the linear combination:或者在multcomp glht中使用 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM