簡體   English   中英

Matlab / R-具有分類和連續預測變量的線性回歸-為什么連續預測變量平方?

[英]Matlab/R - linear regression with categorical & continuous predictors - why is the continuous predictor squared?

我正在使用分類預測變量和0到1的數字結果進行線性回歸。 在此頁面上,我看到它建議在數值預測變量與標稱符號並排時對其求平方(請參閱關於Linear Regression with Categorical Predictor變量的Linear Regression with Categorical Predictor第三部分)。 他們給出的示例(對於Matlab,但這也適用於R)是以下公式,其中weight是連續的, year是標稱的:

mdl = fitlm(tbl,'MPG ~ Year + Weight^2')

這是普遍規則嗎? 當我這樣做時,我確實得到了更強的系數,但是我想確保我不會在沒有認股權證的情況下誇大它們。 有人可以解釋使用.^和數字一起使用數字的邏輯嗎?

如果分別繪制每年的mpg與重量的關系圖,並且看到曲率,則權重的多項式可能有助於校正非線性。

library(lattice)

u <- "https://raw.githubusercontent.com/shifteight/R/master/ISLR/Auto.csv"
Cars <- read.csv(u)

o <- with(Cars, order(year, weight))
xyplot(mpg ~ weight | year, Cars[o, ], type = c("p", "smooth"))

截圖

暫無
暫無

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

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