答案 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