如果您想查看和 (的条件期望)之间的关系是否是线性的,在调整控制变量,一种简单的图形方法是使用以下方法创建一个加变量图程序。yx0x1,x2,…,xp
首先,在并从回归中获得残差。然后,在 回归 X_0并从回归中获得残差。yx1,x2,…,xpϵ^yX0x1,x2,…,xpϵ^x0
对的散点图,并将非参数曲线(例如黄土)与线性回归线重叠。根据Frisch-Waugh 定理的“长”回归完全相同的斜率。非参数曲线将让您了解和之间的关系在多大程度上可以近似为线性。ϵ^yϵ^x0x0,x1,…,xpyx0
一些简单的 R 代码来演示:
data(mtcars)
# full model, with all control variables
fullmod = lm(mpg ~ wt + vs + gear + am, mtcars)
coef(mod)[2]
> wt
> -3.786
# regress y on controls and x on controls, extract residuals
eps_y = lm(mpg ~ vs + gear + am, mtcars)$residuals
eps_x = lm(wt ~ vs + gear + am, mtcars)$residuals
# regress epsilon_y on epsilon_x, see the coef is the same as above
coef(lm(eps_y ~ eps_x))[2]
> eps_y
> -3.786
# make added variable plot
library(ggplot2)
qplot(x = eps_x, y = eps_y) +
geom_smooth(method = "lm", colour = "black", se= FALSE) +
geom_smooth(method = "loess", colour = "red", se = FALSE)