【发布时间】:2019-11-12 11:40:27
【问题描述】:
【问题讨论】:
-
抱歉,我刚刚看到您正在使用 glht。好的,我们可以使用它。下次在你的问题中加入这个?
标签: r statistics regression
【问题讨论】:
标签: r statistics regression
您可以使用 car 包中的 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")
或者使用multcomp包中的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
【讨论】:
car::linearHypothesis 没有提供置信区间(我误读了你的问题)。使用数据框或矩阵。
glht(fit, linfct = "x_3+2*x_5==0")。但这需要有一个数据框,我认为。