最佳答案
你可以用 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
关于r - 如何制作R中回归估计量线性组合的置信区间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58817973/