簡體   English   中英

多元線性回歸中的交互項

[英]interaction terms in multiple linear regression

我已將lm用於我的多元回歸分析。 然后使用GVLMA進行 Assumption 檢驗,結果表明 Global Stat 和 Heteroskedasticity 檢驗不滿足。

代碼形式如下:(所有變量都是連續的)

model_1 <- lm (y ~ x1 + x2, data = abc)

然后我又用相同的變量運行了一個 model(認為我必須引入交互項來修復 GVLMA 假設)

model_2 <- lm (y ~ x1 + x2, x1 * x2, data = abc)

使用這個model_2 ,所有假設都得到滿足。 但是當我檢查時,我意識到引入交互術語的方式並不准確。 我看不到變量之間的“逗號”在這里做什么?

我處於困境,因為 model 非常適合,但我無法解釋, x1 * x2在方程式/結果中的作用?

請幫我理解。

對於線性模型,交互項由:定義,項由+分隔,因此具有單項和交互項的 model 是

lm(y ~ x1:x2 + x1 + x2)

但是,您可以編寫x1*x2 ,其中包括交互和單個效果,因此以下等效於上面

lm(y ~ x1*x2)

看看使用內置數據集 iris 時會發生什么,其中固定效果指定為Petal.Width*Sepal.Length ,所有三個術語都在 model 總結中:

Call:
lm(formula = Petal.Length ~ Petal.Width * Sepal.Length, data = iris)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.99588 -0.24329  0.00355  0.29735  1.24780 

Coefficients:
                         Estimate Std. Error t value Pr(>|t|)    
(Intercept)              -3.24804    0.59586  -5.451 2.08e-07 ***
Petal.Width               2.97115    0.35836   8.291 6.74e-14 ***
Sepal.Length              0.87551    0.11667   7.504 5.60e-12 ***
Petal.Width:Sepal.Length -0.22248    0.06384  -3.485  0.00065 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.3888 on 146 degrees of freedom
Multiple R-squared:  0.9525,    Adjusted R-squared:  0.9515 
F-statistic: 975.4 on 3 and 146 DF,  p-value: < 2.2e-16

至於逗號在模型中的作用,它正在創建一個子集 比較以下三個模型的總結:第一個模型有 146 和 147 個自由度——它們有 150 個數據點,分別估計 4 個和 3 個參數。 第三個 model 模仿您的規格,具有 129 個自由度 - 這就是讓我意識到它是子集的原因。 檢查lm()的文檔,有一個子集參數: lm(formula, data, subset, ...) 因為data是明確指定的,所以未指定的 arguments 默認為formulasubset 您還可以在 model 摘要中看到這一點,該摘要顯示了 model 調用中的一個子集。

summary(lm(Petal.Length ~ Petal.Width * Sepal.Length, data = iris))
summary(lm(Petal.Length ~ Petal.Width + Sepal.Length, data = iris))
summary(lm(Petal.Length ~ Petal.Width + Sepal.Length, Petal.Width * Sepal.Length, data = iris))

你的結果可以通過傳遞這個向量來重新創建, iris$Petal.Width * iris$Sepal.Length作為行號- 所以要小心,這會重復很多行並且也會跳過很多,所以這個 model 的結果不會匹配一個使用所有數據(並且每個數據點僅一次)的。

summary(lm(Petal.Length ~ Petal.Width + Sepal.Length, data = iris[iris$Petal.Width * iris$Sepal.Length, ]))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM