Multiple-Regression

為什麼這個回歸不會因為完美的多重共線性而失敗,儘管一個變量是其他變量的線性組合?

  • February 9, 2016

今天,我在玩一個小數據集並執行了一個簡單的 OLS 回歸,由於完美的多重共線性,我*預計它會失敗。*然而,它沒有。這意味著我對多重共線性的理解是錯誤的。

我的問題是:我哪裡錯了?


我認為我可以證明我的一個變量是其他變量的線性組合。這將導致回歸矩陣沒有滿秩,因此不應識別係數。

我生成了一個小的可重現數據集*(下面的代碼)*:

  exporter importer      flow     dist intraUS
1    Canada   Canada  996.8677 6.367287       0
2   Florida   Canada  995.8219 9.190562       0
3     Texas   Canada 1001.6475 4.359063       0
4    Mexico   Canada 1002.4371 7.476649       0
5    Canada  Florida 1002.8789 5.389223       0
6   Florida  Florida 1007.5589 6.779686       1
7     Texas  Florida  996.8938 1.570600       1
8    Mexico  Florida 1005.6247 5.910133       0
9    Canada    Texas  999.9190 7.887672       0
10  Florida    Texas 1004.1061 7.187803       1
11    Texas    Texas 1004.5949 7.564273       1
12   Mexico    Texas 1000.3728 2.021297       0
13   Canada   Mexico 1003.0991 5.887743       0
14  Florida   Mexico  999.2210 3.058495       0
15    Texas   Mexico  997.6092 6.835883       0
16   Mexico   Mexico 1006.7934 5.794425       0

每次出口商和進口商都是美國各州時,虛擬變量intraUS1

現在我對 (trade) flowsexporterimporter假人、distance 和假人進行回歸intraUS。使用以下公式輸入 R 會lm(flow ~ dist + exporter + importer + intraUS, data = dat)返回所有係數的估計值,沒有缺失值或關於奇點的警告:

(Intercept)            dist exporterFlorida   exporterTexas  exporterMexico importerFlorida   importerTexas  importerMexico        intraUS1 
995.1033157       0.5744661      -1.2340338      -1.8792073       3.7375783       3.0361727       1.3256032       3.3225512       4.2429599

這讓我感到困惑,因為回歸矩陣清楚地表明它intraUSexporterFloridaimporterFloridaexporterTexas的線性組合importerTexas

> mmat <- data.frame(model.matrix(lm(flow ~ dist + exporter + importer + intraUS, data = dat)))

  X.Intercept.     dist exporterFlorida exporterTexas exporterMexico importerFlorida importerTexas importerMexico intraUS1
1             1 6.367287               0             0              0               0             0              0        0
2             1 9.190562               1             0              0               0             0              0        0
3             1 4.359063               0             1              0               0             0              0        0
4             1 7.476649               0             0              1               0             0              0        0
5             1 5.389223               0             0              0               1             0              0        0
6             1 6.779686               1             0              0               1             0              0        1
7             1 1.570600               0             1              0               1             0              0        1
8             1 5.910133               0             0              1               1             0              0        0
9             1 7.887672               0             0              0               0             1              0        0
10            1 7.187803               1             0              0               0             1              0        1
11            1 7.564273               0             1              0               0             1              0        1
12            1 2.021297               0             0              1               0             1              0        0
13            1 5.887743               0             0              0               0             0              1        0
14            1 3.058495               1             0              0               0             0              1        0
15            1 6.835883               0             1              0               0             0              1        0
16            1 5.794425               0             0              1               0             0              1        0

計算exporterFlorida * importerFlorida + exporterFlorida * importerTexas + exporterTexas * importerFlorida + exporterTexas * importerTexas得出 - 毫不奇怪 - 正是intraUS1.

所以我的問題又是:為什麼這個回歸不會失敗,因為一個變量是其他變量的線性組合?


在完整代碼下方重現估計:

## Generate data ####

set.seed(1)
states <- c("Canada", "Florida", "Texas", "Mexico")
dat <- expand.grid(states, states)
colnames(dat) <- c("exporter", "importer")

dat[, "flow"] <- NA
dat[, "dist"] <- NA
dat[, "intraUS"] <- 0

for (i in 1:nrow(dat)) {
 dat[i, c("flow", "dist")] <- c(rnorm(1, mean = 1000, sd = 5), rnorm(1, mean = 6, sd = 2))
 if (dat[i, "exporter"] %in% states[2:3] && dat[i, "importer"] %in% states[2:3]) {
   dat[i, "intraUS"] <- 1
 }
}
dat$intraUS <- factor(dat$intraUS)

## Run regression - works! ####

summary(lm(flow ~ dist + exporter + importer + intraUS, data = dat))

## Show that "intraUS1" is a linear combination of the dummies. ####

mmat <- data.frame(model.matrix(lm(flow ~ dist + exporter + importer + intraUS, data = dat)))

cbind(mmat, test = with(mmat,
                       exporterFlorida * importerFlorida + exporterFlorida * importerTexas +
                       exporterTexas * importerFlorida + exporterTexas * importerTexas
                       ))[, c("intraUS1", "test")]

exporterFlorida * importerFlorida + exporterFlorida * importerTexas + exporterTexas * importerFlorida + exporterTexas * importerTexas

不是exporterFloridaimporterFloridaimporterTexas的線性組合exporterTexas。在線性組合中,向量的係數必須是常數。所以像

2*importerFlorida + 3*importerTexas - exporterFlorida - 2*exporterTexas

線性組合。

你所擁有的可能被稱為二次組合,但這將術語延伸到“我正在編造東西”的領域。

引用自:https://stats.stackexchange.com/questions/194762

comments powered by Disqus