我需要單獨使用空間滯後X(SLX),結合空間自迴歸模型(SAR)或空間誤差模型來估計空間計量經濟模型(SEM)。當它們結合後,它們被稱爲空間Durbin模型(SDM)或空間Durbin誤差模型(SDEM),遵循Elhorst(2015)的論文「The SLX Model」的Vega 。SLX模型 - 使用splm軟件包和礦渣函數的R數據中面板的空間計量經濟學
我打算使用splm包估計R中的所有空間面板模型,這也需要spdep函數。在這個意義上,我創建鄰居列表由形狀鍵入文件張大且k = 4:
> W <- nb2listw(contnbk4, glist = NULL, style = "W")
attributes(W)
$names
[1] "style" "neighbours" "weights"
$class
[1] "listw" "nb"
$region.id
[1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "20"
[21] "21" "22" "23" "24" "25" "26" "27" "28" "29" "30" "31" "32" "33" "34" "35" "36" "37" "38" "39" "40"
[41] "41" "42" "43" "44" "45" "46" "47" "48" "49" "50" "51" "52" "53" "54" "55" "56" "57" "58" "59" "60"
[61] "61" "62" "63" "64" "65" "66" "67" "68" "69" "70" "71" "72" "73" "74" "75" "76" "77" "78" "79" "80"
[81] "81" "82" "83" "84" "85" "86" "87" "88" "89" "90" "91" "92" "93" "94" "95" "96" "97" "98" "99" "100"
[101] "101" "102" "103" "104" "105" "106" "107" "108" "109" "110" "111" "112" "113" "114" "115" "116" "117" "118" "119" "120"
[121] "121" "122" "123" "124" "125" "126" "127" "128" "129" "130" "131" "132" "133" "134" "135" "136" "137" "138" "139" "140"
[141] "141" "142" "143" "144" "145" "146" "147" "148" "149" "150" "151" "152" "153" "154" "155" "156" "157" "158" "159" "160"
[161] "161" "162" "163" "164" "165" "166" "167" "168" "169" "170" "171" "172" "173" "174" "175" "176" "177" "178" "179" "180"
[181] "181" "182" "183" "184" "185" "186" "187" "188" "189" "190" "191" "192" "193" "194" "195" "196" "197" "198" "199" "200"
[201] "201" "202" "203" "204" "205" "206" "207" "208" "209" "210" "211" "212" "213" "214" "215" "216" "217" "218" "219" "220"
[221] "221" "222" "223" "224" "225" "226" "227" "228" "229" "230" "231" "232" "233" "234" "235" "236" "237" "238" "239" "240"
[241] "241" "242" "243" "244" "245" "246" "247" "248" "249" "250" "251" "252" "253" "254" "255" "256" "257" "258" "259" "260"
[261] "261" "262" "263" "264" "265" "266" "267" "268" "269" "270" "271" "272" "273" "274" "275" "276"
$call
nb2listw(neighbours = contnbk7, glist = NULL, style = "W")
下一步,我創建一個:
> TCAL <- readOGR(dsn = ".", "Municipios_csv")
> coords <- coordinates(TCAL)
> contnbQueen <- poly2nb(TCAL, queen = TRUE)
> enter code herecontnbk4 <- knn2nb(knearneigh(coords, k = 4, RANN = FALSE))
然後我在權重矩陣轉換此鄰居列表公式面板SAR和SEM模型,它運作良好,產生估算值:
> fmPanel <- Area ~ Dist + Land + CredAg
> vegSAR <- spml(fmPanel, data = veg, index = c("Mun","Year"), listw = W, model = "within", effect = "twoways", spatial.error = "none", lag = TRUE)
> vegSEM <- spml(fmPanel, data = veg, index = c("Mun","Year"), listw = W, model = "within", effect = "twoways", spatial.error = "b", lag = FALSE)
然後,我試圖通過創建協變量X的空間滯後估計SLX,SDM和SDEM機型:
> vegX <- pdata.frame(veg, index = c("Mun","Year")); class(vegX)
[1] "pdata.frame" "data.frame"
然後我創建的pSeries值:
> DistX <- vegX$Dist; class(DistX)
[1] "pseries" "numeric"
> LandX <- vegX$Land; class(LandX)
[1] "pseries" "numeric"
> CredAgX <- vegX$CredAg; class(CredAgX)
[1] "pseries" "numeric"
但是當我申請發生的錯誤渣功能:
DistX <- slag(agSPX$Dist, listw = W)
Error in lag.listw(listw, xt) : object lengths differ
我的面板數據,有5年,276個區。所以,對象特點是:
> length(DistX)
[1] 1380
> length(W)
[1] 3
> length(W$weights)
[1] 276
所以,我在想,如果我能在一個矩陣變換矩陣W $權重如usaww作爲例子渣功能,我可以申請功能mat2listw和然後在X上使用爐渣。
有人能告訴我我錯在哪?