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

标签 r statistics regression

在这个回归中:

enter image description here

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

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

添加了这个

enter image description here

最佳答案

你可以用 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")

或与 glhtmultcomp包,它还提供了线性组合的置信区间:
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

关于r - 如何制作R中回归估计量线性组合的置信区间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58817973/

相关文章:

RStudio、Packrat 和 Knir

r - 如何基于 data.table 中的分类变量以编程方式创建二进制列?

python - pandas DataFrame 中的操作

statistics - 如何从此函数获得一致的返回类型?

machine-learning - 向 MatConvNet 添加回归层

javascript - 当在服务器中构建 colorInput 时,R Shiny 使用 javascript 绘制地更新跟踪颜色

r - 独立转换多列

对频率列表进行 t 检验的 Python 程序

fitdistr函数返回值解释

python - 如何提高 R 在机器学习中的性能?