包含交互项的线性模型的部分残差图 [英] Partial residual plots for linear model including an interaction term

查看:50
本文介绍了包含交互项的线性模型的部分残差图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的模型包含一个响应变量、五个预测变量以及一个用于 predictor_1 和 predictor_2 的交互项.我想为我通常使用 car 包中的 crPlots 函数实现的每个预测变量绘制部分残差图.不幸的是,该函数抱怨它不适用于包含交互项的模型.

My model includes one response variable, five predictors and one interaction term for predictor_1 and predictor_2. I would like to plot partial residual plots for every predictor variable which I would normally realize using the crPlots function from the package car. Unfortunately the function complains that it doesn't work with models that include interaction terms.

还有其他方法可以做我想做的事吗?

Is there another way of doing what I want?

我创建了一个说明问题的小例子

I created a small example illustrating the problem

require(car)
R <-  c(0.53,0.60,0.64,0.52,0.75,0.66,0.71,0.49,0.52,0.59)
P1 <- c(3.1,1.8,1.8,1.8,1.8,3.2,3.2,2.8,3.1,3.3)
P2 <- c(2.1,0.8,0.3,0.5,0.4,1.3,0.5,1.2,1.6,2.1)

lm.fit1 <- lm(R ~ P1 + P2)
summary(lm.fit1)
crPlots(lm.fit1) # works fine

lm.fit2 <- lm(R ~ P1*P2)
summary(lm.fit2)
crPlots(lm.fit2) # not available

推荐答案

另一种方法是将交互项作为单独的变量放入(这样可以避免对 crPlot(...)).

Another way to do this is to put the interaction term in as a separate variable (which avoids hacking the code for crPlot(...)).

df <- data.frame(R,P1,P2,P1.P2=P1*P2)
lm.fit1 <- lm(R ~ ., df)
summary(lm.fit1)
crPlots(lm.fit1)

请注意,summary(lm.fit1) 产生的结果与 summary(lm(R~P1*P2,df)) 完全相同.

Note that summary(lm.fit1) yeilds exactly the same result as summary(lm(R~P1*P2,df)).

这篇关于包含交互项的线性模型的部分残差图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆