本文介绍了获得"mlm"回归系数的置信区间.lm()返回的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用2个结果变量和5个预测变量进行多元回归.我想获得所有回归系数的置信区间.通常我使用函数 lm 但它似乎不适用于多元回归模型(对象 mlm).

I'm running a multivariate regression with 2 outcome variables and 5 predictors. I would like to obtain the confidence intervals for all regression coefficients. Usually I use the function lm but it doesn't seem to work for a multivariate regression model (object mlm).

这是一个可复制的示例.

Here's a reproducible example.

library(car)
mod <- lm(cbind(income, prestige) ~ education + women, data=Prestige)
confint(mod) # doesn't return anything.

有其他替代方法吗?(我可以只使用标准误差的值,然后乘以正确的临界t值,但我想知道是否有更简单的方法来做到这一点.)

Any alternative way to do it? (I could just use the value of the standard error and multiply by the right critical t value, but I was wondering if there was an easier way to do it).

推荐答案

confint 不会返回任何内容,因为不支持"mlm"方法:

confint won't return you anything, because there is no "mlm" method supported:

methods(confint)
#[1] confint.default confint.glm*    confint.lm      confint.nls*

正如您所说,我们可以加/减一些标准误差来获得置信区间的上限/下限.您可能打算通过 coef(summary(mod))进行此操作,然后使用某些 * apply 方法提取标准错误.但是我的回答 达到标准由 lm() 返回的"mlm"对象的回归系数误差为您提供了一种无需通过 summary 即可获得标准误差的高效方法.将 std_mlm 应用于示例模型可以得到:

As you said, we can just plus / minus some multiple of standard error to get upper / lower bound of confidence interval. You were probably going to do this via coef(summary(mod)), then use some *apply method to extract standard errors. But my answer to Obtain standard errors of regression coefficients for an "mlm" object returned by lm() gives you a supper efficient way to get standard errors without going through summary. Applying std_mlm to your example model gives:

se <- std_mlm(mod)
#                 income   prestige
#(Intercept) 1162.299027 3.54212524
#education    103.731410 0.31612316
#women          8.921229 0.02718759

现在,我们定义另一个小函数来计算上下限:

Now, we define another small function to compute lower and upper bound:

## add "mlm" method to generic function "confint"
confint.mlm <- function (model, level = 0.95) {
  beta <- coef(model)
  se <- std_mlm (model)
  alpha <- qt((1 - level) / 2, df = model$df.residual)
  list(lower = beta + alpha * se, upper = beta - alpha * se)
  }

## call "confint"
confint(mod)

#$lower
#                 income    prestige
#(Intercept) -3798.25140 -15.7825086
#education     739.05564   4.8005390
#women         -81.75738  -0.1469923
#
#$upper
#                income    prestige
#(Intercept)  814.25546 -1.72581876
#education   1150.70689  6.05505285
#women        -46.35407 -0.03910015

这很容易解释.例如,对于响应收入,所有变量的95%置信区间为

It is easy to interpret this. For example, for response income, the 95%-confidence interval for all variables are

#(intercept)    (-3798.25140, 814.25546)
#  education    (739.05564, 1150.70689)
#      women    (-81.75738, -46.35407)

这篇关于获得"mlm"回归系数的置信区间.lm()返回的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 17:12