Painel Espacial com R: reproduzindo Millo e Piras (2012)
Painel Espacial com R: reproduzindo Millo e Piras (2012)
- Licença
- Citação
- 1 Introdução
- 2 Pacotes necessários
- 3 Dados
- 4 O modelo do PIB estadual dos EUA
- 4.1 Regressão espacial e Matriz de vizinhança
- 4.2 Regressão espacial com efeitos aleatórios: Random Effects
- 4.3 Regressão espacial com efeito fixos: Fixed Effects
- 4.4 Painel espacial com Momentos Generalizados (Spatial Panel with Generalized Moments - GM)
- 4.5 Testes no modelo
- 4.6 Spatial Hausman Test (sphtest)
- 4.7 Teste de significância dos coeficientes
- 5 Exemplo Cigarros
- Referências
Licença
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
License: CC BY-SA 4.0
As ideias aqui expressas são de responsabilidade exclusiva do autor, e não representam as opiniões da instituição a que pertence.
Citação
Sugestão para citação: Figueiredo, Adriano Marcos Rodrigues. Painel Espacial com R: reproduzindo Millo e Piras (2012). Campo Grande-MS,Brasil: RStudio/Rpubs, 2019. Disponível em http://rpubs.com/amrofi/spatial_panel_with_R.
1 Introdução
Este paper faz a reprodução do script do artigo de Millo and Piras (2012),
Giovanni Millo, Gianfranco Piras (2012). splm: Spatial Panel Data Models in
R. Journal of Statistical Software, 47(1), 1-38. URL
http://www.jstatsoft.org/v47/i01/.
Os scripts e arquivos de dados devem ser baixados no site do artigo e colocados no mesmo diretório de trabalho onde executará os presentes códigos.
2 Pacotes necessários
A rotina abaixo carregará o pacote, caso esteja previamente instalado, ou realizará a instalação caso seja necessário.
# pacotes necessários
pkgs <- c("car","dplyr","DT","Ecdat","knitr",
"lmtest","magrittr","spdep","splm","tidyr")
for (p in pkgs) {
if (inherits(try(suppressMessages(library(p, character.only = TRUE))),
"try-error"))
install.packages(p, character.only = TRUE)
}
### set options
options(prompt = "R> ", continue = "+ ",
width = 70, useFancyQuotes = FALSE)
3 Dados
Os dados utilizados serão do pacote Ecdat
, um painel de 48 observações estaduais e anuais de 1970 a 1986, para os Estados Unidos, perfazendo um total de 816 observações.
O dataframe tem por base o painel de Rasmussen (2003):
state - estado dos Estados Unidos;
year - ano;
pcap - estoque de capital privado;
hwy - ruas e vias expressas;
water - instalações de água e esgoto;
util - outros edifícios e estruturas públicas;
pc - capital público;
gsp - produtos estaduais brutos (PIB estadual);
emp - insumo do trabalho medido pelo emprego nas folhas de pagamento não agrícolas; e,
unemp - taxa de desemprego do estado.
Fonte:
Munnell, A. (1990) “Why has productivity growth declined? Productivity and public investment”, New England Economic Review, 3–22.
Baltagi, B. H. and N. Pinnoi (1995) “Public capital stock and state productivity growth: further evidence”, Empirical Economics, 20, 351–359.
4 O modelo do PIB estadual dos EUA
4.1 Regressão espacial e Matriz de vizinhança
Os modelos espaciais com dados de paineis são comumente classificados em efeitos aleatórios (random) e efeitos fixos (fixed). A fórmula a ser estimada, o modelo proveniente do modelo teórico é:
A matriz de vizinhança aqui é dada pelo pacote spdep
.
4.2 Regressão espacial com efeitos aleatórios: Random Effects
Também chamado de Modelo SARARRE - Spatial Autorregressive model with Autorregressive Errors and Random Effects, a estimação de Máxima Verossimilhança (ML) do painel espacial com modelo de efeitos aleatórios (random effects) é realizada com a função spml
e model = "random"
, para formula = fm
e o comando listw = usaw
indica a matriz de vizinhança. O lag = TRUE
indica a inclusão da variável dependente defasada espacialmente (ou seja, neste caso, o lag da variável log(gsp)
. O comando spatial.error = "b"
indica o tipo de correlação espacial do erro (spatial error correlation) na especificação, neste caso, de Baltagi. Outra alternativa seria com spatial.error = "kkp"
para a especificação de Kapoor et al (2007) (Kapoor, Kelejian e Prucha), ou spatial.error = "none"
para nenhuma.
# Spatial panel random effects ML model (Baltagi)
# ML panel with spatial lag, random effects, spatial error correlation
### spreml1
sararremod <- spml(formula = fm, data = Produc, index = NULL, listw = usalw, model = "random", lag = TRUE, spatial.error = "b")
summary(sararremod)
## ML panel with spatial lag, random effects, spatial error correlation
##
## Call:
## spreml(formula = formula, data = data, index = index, w = listw2mat(listw),
## w2 = listw2mat(listw2), lag = lag, errors = errors, cl = cl)
##
## Residuals:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.2477 -0.0411 0.0123 0.0191 0.0727 0.4841
##
## Error variance parameters:
## Estimate Std. Error t-value Pr(>|t|)
## phi 7.53078 1.85638 4.0567 4.977e-05 ***
## rho 0.53683 0.05603 9.5811 < 2.2e-16 ***
##
## Spatial autoregressive coefficient:
## Estimate Std. Error t-value Pr(>|t|)
## lambda 0.0018204 0.0400679 0.0454 0.9638
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## (Intercept) 2.3735772 0.1394744 17.0180 < 2.2e-16 ***
## log(pcap) 0.0425017 0.0222146 1.9132 0.055719 .
## log(pc) 0.2415075 0.0202970 11.8987 < 2.2e-16 ***
## log(emp) 0.7419063 0.0244212 30.3796 < 2.2e-16 ***
## unemp -0.0034560 0.0010605 -3.2589 0.001118 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Agora com a mesma fórmula e função spml
, alterando o argumento spatial.error
para refletir os resultados de Kapoor et al. (2007):
# Spatial panel random effects ML model - (Kapoor, Kelejian e Prucha, KKP)
# ML panel with , spatial RE (KKP), spatial error correlation
### spreml2
semremod <- spml(formula = fm, data = Produc, index = NULL,
listw = usalw,
model = "random",
lag = FALSE,
spatial.error = "kkp")
summary(semremod)
## ML panel with , spatial RE (KKP), spatial error correlation
##
## Call:
## spreml(formula = formula, data = data, index = index, w = listw2mat(listw),
## w2 = listw2mat(listw2), lag = lag, errors = errors, cl = cl)
##
## Residuals:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.27000 -0.06425 -0.01118 -0.00448 0.04889 0.46937
##
## Error variance parameters:
## Estimate Std. Error t-value Pr(>|t|)
## phi 6.624775 1.549683 4.2749 1.912e-05 ***
## rho 0.526465 0.033338 15.7917 < 2.2e-16 ***
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## (Intercept) 2.3246707 0.1415894 16.4184 < 2.2e-16 ***
## log(pcap) 0.0445475 0.0220377 2.0214 0.0432362 *
## log(pc) 0.2461124 0.0211341 11.6453 < 2.2e-16 ***
## log(emp) 0.7426319 0.0254663 29.1614 < 2.2e-16 ***
## unemp -0.0036045 0.0010637 -3.3887 0.0007022 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
4.3 Regressão espacial com efeito fixos: Fixed Effects
Primeiro estima-se o modelo com efeitos within
, ou seja, model = within
para indicar que os efeitos fixos são transformados para eliminar os efeitos individuais.
A função spml
tem a opção de estimar um modelo com efeitos espaciais tanto lag
como error
, combinando os argumentos lag
como spatial.error
.
# Spatial panel fixed effects sarar model
### spfeml
sararfemod <- spml(formula = fm, data = Produc, index = NULL,
listw = usalw,
lag = TRUE,
spatial.error= "b",
model = "within",
effect = "individual",
method = "eigen",na.action = na.fail,
quiet = TRUE,zero.policy=NULL,
tol.solve = 1e-10, control = list(),
legacy = FALSE)
summary(sararfemod)
## Spatial panel fixed effects sarar model
##
##
## Call:
## spml(formula = fm, data = Produc, index = NULL, listw = usalw,
## na.action = na.fail, model = "within", effect = "individual",
## lag = TRUE, spatial.error = "b", method = "eigen", quiet = TRUE,
## zero.policy = NULL, tol.solve = 1e-10, control = list(),
## legacy = FALSE)
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.1335552 -0.0220919 -0.0032048 0.0171787 0.1748911
##
## Spatial error parameter:
## Estimate Std. Error t-value Pr(>|t|)
## rho 0.455312 0.042538 10.704 < 2.2e-16 ***
##
## Spatial autoregressive coefficient:
## Estimate Std. Error t-value Pr(>|t|)
## lambda 0.088576 0.026312 3.3663 0.0007618 ***
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## log(pcap) -0.0103497 0.0255345 -0.4053 0.6852
## log(pc) 0.1905781 0.0242829 7.8483 4.219e-15 ***
## log(emp) 0.7552372 0.0290385 26.0081 < 2.2e-16 ***
## unemp -0.0030613 0.0010315 -2.9678 0.0030 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Outra especificação indica o modelo apenas com efeitos fixos individuais (na cross-section) (effect = "individual"
), sem dependência espacial nos erros e na variável dependente. Os efeitos fixos são obtidos com a função effects
.
### spfeml2
sarfemod <- spml(formula = fm, data = Produc, index = NULL, listw = usalw, model="within", effect = "individual", method = "eigen", na.action = na.fail, quiet = TRUE, zero.policy = NULL, tol.solve = 1e-10, control = list(), legacy = FALSE )
summary(sarfemod)
## Spatial panel fixed effects error model
##
##
## Call:
## spml(formula = fm, data = Produc, index = NULL, listw = usalw,
## na.action = na.fail, model = "within", effect = "individual",
## method = "eigen", quiet = TRUE, zero.policy = NULL, tol.solve = 1e-10,
## control = list(), legacy = FALSE)
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.1246945 -0.0237699 -0.0034993 0.0170886 0.1882224
##
## Spatial error parameter:
## Estimate Std. Error t-value Pr(>|t|)
## rho 0.557401 0.033075 16.853 < 2.2e-16 ***
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## log(pcap) 0.0051438 0.0250109 0.2057 0.83705
## log(pc) 0.2053026 0.0231427 8.8712 < 2e-16 ***
## log(emp) 0.7822540 0.0278057 28.1328 < 2e-16 ***
## unemp -0.0022317 0.0010709 -2.0839 0.03717 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
O modelo pode ter efeitos fixos no tempo (effect = "time"
). Os efeitos fixos no tempo podem ser extraídos pela função effects
.
# Spatial error model with time period fixed effects
### spfeml3
semfemod <- spml(formula = fm, data = Produc, listw = usalw,model="within", effect = "time", method = "eigen", na.action = na.fail, quiet = TRUE, zero.policy = NULL, tol.solve = 1e-10, control = list(), legacy = FALSE )
summary(semfemod)
## Spatial panel fixed effects error model
##
##
## Call:
## spml(formula = fm, data = Produc, listw = usalw, na.action = na.fail,
## model = "within", effect = "time", method = "eigen", quiet = TRUE,
## zero.policy = NULL, tol.solve = 1e-10, control = list(),
## legacy = FALSE)
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.21855239 -0.06447207 -0.00059156 0.05541491 0.31721113
##
## Spatial error parameter:
## Estimate Std. Error t-value Pr(>|t|)
## rho 0.496230 0.035791 13.865 < 2.2e-16 ***
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## log(pcap) 0.1432725 0.0165720 8.6455 < 2.2e-16 ***
## log(pc) 0.3636539 0.0109631 33.1707 < 2.2e-16 ***
## log(emp) 0.5619649 0.0143684 39.1113 < 2.2e-16 ***
## unemp -0.0078930 0.0018665 -4.2288 2.349e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Intercept:
## Estimate Std. Error t-value Pr(>|t|)
## (Intercept) 1.412536 0.050965 27.716 < 2.2e-16 ***
##
##
## Time period fixed effects:
## Estimate Std. Error t-value Pr(>|t|)
## 1 -0.00515318 0.05167995 -0.0997 0.9206
## 2 0.00103556 0.05200686 0.0199 0.9841
## 3 0.01161188 0.05193737 0.2236 0.8231
## 4 0.02086866 0.05182860 0.4026 0.6872
## 5 -0.01243892 0.05194369 -0.2395 0.8107
## 6 -0.01638407 0.05254389 -0.3118 0.7552
## 7 -0.01602721 0.05238016 -0.3060 0.7596
## 8 -0.00817852 0.05217527 -0.1568 0.8754
## 9 -0.00108650 0.05184557 -0.0210 0.9833
## 10 -0.00714318 0.05177969 -0.1380 0.8903
## 11 -0.02071186 0.05204947 -0.3979 0.6907
## 12 -0.00791710 0.05222694 -0.1516 0.8795
## 13 -0.01409039 0.05284233 -0.2666 0.7897
## 14 0.00042906 0.05286077 0.0081 0.9935
## 15 0.01861529 0.05225588 0.3562 0.7217
## 16 0.02531034 0.05216326 0.4852 0.6275
## 17 0.03126013 0.05219134 0.5990 0.5492
4.4 Painel espacial com Momentos Generalizados (Spatial Panel with Generalized Moments - GM)
4.4.1 Painel Espacial GM, Random Effects, com erro espacial e sem lag espacial
# erro espacial sem lag espacial
### spregm
GM_error <- spgm(formula = fm, data = Produc, listw = usaww, moments = "fullweights", model="random", spatial.error = TRUE)
summary(GM_error)
##
##
## Call:
## spgm(formula = fm, data = Produc, listw = usaww, model = "random",
## spatial.error = TRUE, moments = "fullweights")
##
## Residuals:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.26628 -0.06564 -0.00717 -0.00480 0.04855 0.45897
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## (Intercept) 2.2273357 0.1350953 16.4871 < 2.2e-16 ***
## log(pcap) 0.0540212 0.0219722 2.4586 0.0139474 *
## log(pc) 0.2565921 0.0209342 12.2571 < 2.2e-16 ***
## log(emp) 0.7278231 0.0252309 28.8464 < 2.2e-16 ***
## unemp -0.0038108 0.0011004 -3.4630 0.0005341 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
4.4.2 Painel Espacial GM, Random Effects, com erro espacial e com lag espacial
# Spatial Panel with Generalized Moments
# Com erro espacial e lag espacial
### spregm
GM_full <- spgm(formula = fm, data = Produc, listw = usaww, moments = "fullweights", model="random", spatial.error = TRUE, lag = TRUE)
summary(GM_full)
##
##
## Call:
## spgm(formula = fm, data = Produc, listw = usaww, model = "random",
## lag = TRUE, spatial.error = TRUE, moments = "fullweights")
##
## Residuals:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.27454 -0.06044 -0.00201 -0.00187 0.05255 0.47031
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## lambda 0.02232364 0.01348213 1.6558 0.09776 .
## (Intercept) 2.01385829 0.16738225 12.0315 < 2.2e-16 ***
## log(pcap) 0.04629075 0.02245615 2.0614 0.03927 *
## log(pc) 0.26657382 0.02033903 13.1065 < 2.2e-16 ***
## log(emp) 0.72124148 0.02472888 29.1660 < 2.2e-16 ***
## unemp -0.00517520 0.00097115 -5.3289 9.88e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
4.4.3 Painel Espacial GM, Fixed Effects, com erro espacial e com lag espacial
# Spatial panel fixed effects GM model
### spregm
GM_error <- spgm(formula = fm, data = Produc, lag = TRUE, listw = usaww, model="within", spatial.error = TRUE)
summary(GM_error)
## Spatial panel fixed effects GM model
##
##
## Call:
## spgm(formula = fm, data = Produc, listw = usaww, model = "within",
## lag = TRUE, spatial.error = TRUE)
##
## Residuals:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.82 2.09 2.19 2.20 2.29 2.70
##
## Estimated spatial coefficient, variance components and theta:
## Estimate
## rho 0.3254804
## sigma^2_v 0.0011306
##
## Spatial autoregressive coefficient:
## Estimate Std. Error t-value Pr(>|t|)
## lambda 0.132709 0.024593 5.3963 6.803e-08 ***
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## log(pcap) -0.0205827 0.0268688 -0.7660 0.4436500
## log(pc) 0.1936870 0.0255383 7.5842 3.346e-14 ***
## log(emp) 0.7291745 0.0303750 24.0058 < 2.2e-16 ***
## unemp -0.0037004 0.0010235 -3.6154 0.0002999 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
4.5 Testes no modelo
A função bsktest
permite calcular os testes (conjunta, marginal ou condicional) de efeitos aleatórios e correlação espacial nos erros. São cinco opções correspondentes a Baltagi, Song, and Koh (2003), a saber: “LM1”, “LM2”, “LMJOINT”, “CLMlambda” e “CLMmu”.
4.5.1 LM1
# Baltagi, Song and Koh SLM1 marginal test
### bsklmtest1
test1<-bsktest(x = fm, data = Produc, listw = mat2listw(usaww), test = "LM1")
print(class(test1))
## [1] "htest"
##
## Baltagi, Song and Koh SLM1 marginal test
##
## data: log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp
## LM1 = 64.304, p-value < 2.2e-16
## alternative hypothesis: Random effects
4.5.2 LM2
# Baltagi, Song and Koh LM2 marginal test
### bsklmtest2
test2<-bsktest(x = fm, data = Produc, listw = mat2listw(usaww), test = "LM2")
test2
##
## Baltagi, Song and Koh LM2 marginal test
##
## data: log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp
## LM2 = 11.657, p-value < 2.2e-16
## alternative hypothesis: Spatial autocorrelation
4.5.3 CLM lambda
# Baltagi, Song and Koh LM*-lambda conditional LM test
### bsklmtest3
bsktest(x = fm, data = Produc, listw = mat2listw(usaww), test = "CLMlambda")
##
## Baltagi, Song and Koh LM*-lambda conditional LM test
## (assuming sigma^2_mu >= 0)
##
## data: log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp
## LM*-lambda = 14.436, p-value < 2.2e-16
## alternative hypothesis: Spatial autocorrelation
4.6 Spatial Hausman Test (sphtest)
O teste de Hausman é usado para comparar os estimadores de efeitos fixos com os aleatórios para saber se a pressuposição de efeitos aleatórios é aceita pelos dados. Os estimadores do modelo “within” são comparados com o GLS espacial com uma estatística de teste do tipo \(\chi^2\) com k graus de liberdade em que k é o número de regressores do modelo.
4.6.1 sphtest1
### sphtest1
test1<-sphtest(x = fm, data = Produc, listw = mat2listw(usaww), spatial.model = "error", method = "GM")
test1
##
## Hausman test for spatial models
##
## data: x
## chisq = 31.151, df = 4, p-value = 2.852e-06
## alternative hypothesis: one model is inconsistent
4.6.2 sphtest2
Esta opção evidencia que os dois modelos podem ser especificados entre os argumentos da função, caso os modelos tenham sido estimados separadamente.
### sphtest2
# Random
mod1<- spgm(formula = fm, data = Produc, listw = usaww, moments = "fullweights", model = "random", spatial.error = TRUE, lag = TRUE)
# Within (fixed)
mod2<- spgm(formula = fm, data = Produc, listw = usaww, model = "within", spatial.error = TRUE, lag = TRUE)
test2<-sphtest(x = mod1, x2 = mod2)
test2
##
## Hausman test for spatial models
##
## data: fm
## chisq = 41.897, df = 5, p-value = 6.18e-08
## alternative hypothesis: one model is inconsistent
4.7 Teste de significância dos coeficientes
##
## z test of coefficients:
##
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 2.3735772 0.1394744 17.0180 < 2.2e-16 ***
## log(pcap) 0.0425017 0.0222146 1.9132 0.055719 .
## log(pc) 0.2415075 0.0202970 11.8987 < 2.2e-16 ***
## log(emp) 0.7419063 0.0244212 30.3796 < 2.2e-16 ***
## unemp -0.0034560 0.0010605 -3.2589 0.001118 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
4.7.1 Teste da igualdade da elasticidade de crescimento do capital público (pcap) e capital privado (pc)
5 Exemplo Cigarros
5.1 Modelo
5.2 Modelos em painel e com efeitos espaciais
## Fixed effects SAR
sarfe <- spml(formula = fm, data = cigar, listw = lwcig, model = "within",
effect = "individual",
spatial.error = "none", lag = TRUE)
summary(sarfe)
## Spatial panel fixed effects lag model
##
##
## Call:
## spml(formula = fm, data = cigar, listw = lwcig, model = "within",
## effect = "individual", lag = TRUE, spatial.error = "none")
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.11014656 -0.02370245 -0.00094553 0.02382706 0.15797342
##
## Spatial autoregressive coefficient:
## Estimate Std. Error t-value Pr(>|t|)
## lambda 0.198648 0.067391 2.9477 0.003202 **
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## logp -0.608614 0.048101 -12.6529 < 2.2e-16 ***
## logpn 0.232903 0.065469 3.5575 0.0003745 ***
## logy 0.294722 0.038226 7.7099 1.259e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Fixed effects SEM
semfe <- spml(formula = fm, data = cigar, listw = lwcig, model = "within",
effect = "individual",
spatial.error = "b", lag = FALSE)
summary(semfe)
## Spatial panel fixed effects error model
##
##
## Call:
## spml(formula = fm, data = cigar, listw = lwcig, model = "within",
## effect = "individual", lag = FALSE, spatial.error = "b")
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.09893082 -0.02681578 -0.00099112 0.02422114 0.14963824
##
## Spatial error parameter:
## Estimate Std. Error t-value Pr(>|t|)
## rho 0.302676 0.070229 4.3099 1.634e-05 ***
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## logp -0.618338 0.046913 -13.1806 < 2.2e-16 ***
## logpn 0.128986 0.064097 2.0124 0.04418 *
## logy 0.335879 0.044932 7.4753 7.702e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Random effects SAR
sarre <- spml(formula = fm, data = cigar, listw = lwcig, model = "random",
spatial.error = "none", lag = TRUE)
summary(sarre)
## ML panel with spatial lag, random effects
##
## Call:
## spreml(formula = formula, data = data, index = index, w = listw2mat(listw),
## w2 = listw2mat(listw2), lag = lag, errors = errors, cl = cl)
##
## Residuals:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.261 0.771 0.847 0.870 0.932 1.650
##
## Error variance parameters:
## Estimate Std. Error t-value Pr(>|t|)
## phi 20.3341 4.7178 4.3101 1.632e-05 ***
##
## Spatial autoregressive coefficient:
## Estimate Std. Error t-value Pr(>|t|)
## lambda 0.181275 0.061912 2.9279 0.003412 **
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## (Intercept) 2.521162 0.170026 14.8281 < 2.2e-16 ***
## logp -0.618952 0.052152 -11.8683 < 2.2e-16 ***
## logpn 0.228368 0.065218 3.5016 0.0004624 ***
## logy 0.313567 0.038295 8.1882 2.651e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Random effects SEM
semre <- spml(formula = fm, data = cigar, listw = lwcig, model = "random",
spatial.error = "b", lag = FALSE)
summary(semre)
## ML panel with , random effects, spatial error correlation
##
## Call:
## spreml(formula = formula, data = data, index = index, w = listw2mat(listw),
## w2 = listw2mat(listw2), lag = lag, errors = errors, cl = cl)
##
## Residuals:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.60011 -0.09489 -0.01757 -0.00001 0.05193 0.78684
##
## Error variance parameters:
## Estimate Std. Error t-value Pr(>|t|)
## phi 21.269291 4.948478 4.2981 1.722e-05 ***
## rho 0.310914 0.073819 4.2119 2.533e-05 ***
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## (Intercept) 3.157798 0.212812 14.8385 < 2.2e-16 ***
## logp -0.629792 0.050629 -12.4393 < 2.2e-16 ***
## logpn 0.123491 0.068410 1.8052 0.07105 .
## logy 0.361601 0.047713 7.5787 3.49e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
5.3 Modelos com dados empilhados (apenas efeitos espaciais)
## Pooling SAR
sarpool <- spml(formula = fm, data = cigar, listw = lwcig, model = "pooling",
spatial.error = "none", lag = TRUE)
summary(sarpool)
## ML panel with spatial lag and iid errors
##
## Call:
## spreml(formula = formula, data = data, index = index, w = listw2mat(listw),
## w2 = listw2mat(listw2), lag = lag, errors = errors, cl = cl)
##
## Residuals:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.209 0.299 0.386 0.395 0.467 1.105
##
## Spatial autoregressive coefficient:
## Estimate Std. Error t-value Pr(>|t|)
## lambda 0.082250 0.058619 1.4031 0.1606
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## (Intercept) 1.304801 0.291914 4.4698 7.829e-06 ***
## logp -1.038347 0.119610 -8.6811 < 2.2e-16 ***
## logpn 0.180146 0.122931 1.4654 0.1428
## logy 0.683452 0.065246 10.4750 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Pooling SEM
sempool <- spml(formula = fm, data = cigar, listw = lwcig, model = "pooling",
spatial.error = "b", lag = FALSE)
summary(sempool)
## ML panel with , spatial error correlation
##
## Call:
## spreml(formula = formula, data = data, index = index, w = listw2mat(listw),
## w2 = listw2mat(listw2), lag = lag, errors = errors, cl = cl)
##
## Residuals:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.60762 -0.09700 -0.00801 0.00024 0.07633 0.70739
##
## Error variance parameters:
## Estimate Std. Error t-value Pr(>|t|)
## rho 0.147554 0.067699 2.1796 0.02929 *
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## (Intercept) 1.484186 0.312829 4.7444 2.091e-06 ***
## logp -1.060385 0.118173 -8.9732 < 2.2e-16 ***
## logpn 0.150483 0.125306 1.2009 0.2298
## logy 0.730092 0.069817 10.4572 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Transformando a matriz de proximidade empilhada em um objeto tipo 'listw'
pool.lwcig <- mat2listw(kronecker(diag(1,6),listw2mat(lwcig)))
summary(pool.lwcig)
## Characteristics of weights list object:
## Neighbour list object:
## Number of regions: 276
## Number of nonzero links: 1128
## Percentage nonzero weights: 1.480781
## Average number of links: 4.086957
## Link number distribution:
##
## 1 2 3 4 5 6 7 8
## 18 24 54 66 72 24 12 6
## 18 least connected regions:
## 17 36 43 63 82 89 109 128 135 155 174 181 201 220 227 247 266 273 with 1 link
## 6 most connected regions:
## 23 69 115 161 207 253 with 8 links
##
## Weights style: M
## Weights constants summary:
## n nn S0 S1 S2
## M 276 76176 276 154.3387 1148.968
## Pooling SAR pelo pacote 'spdep'
sarpool.2 <- lagsarlm(formula = fm, data = cigar, listw = pool.lwcig)
summary(sarpool.2)
##
## Call:lagsarlm(formula = fm, data = cigar, listw = pool.lwcig)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.6124792 -0.0951589 -0.0060833 0.0732741 0.7047066
##
## Type: lag
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 1.304801 0.360331 3.6211 0.0002933
## logp -1.038347 0.119958 -8.6559 < 2.2e-16
## logpn 0.180146 0.125899 1.4309 0.1524658
## logy 0.683452 0.070304 9.7213 < 2.2e-16
##
## Rho: 0.08225, LR test value: 1.9474, p-value: 0.16286
## Asymptotic standard error: 0.069537
## z-value: 1.1828, p-value: 0.23688
## Wald statistic: 1.3991, p-value: 0.23688
##
## Log likelihood: 86.52832 for lag model
## ML residual variance (sigma squared): 0.031223, (sigma: 0.1767)
## Number of observations: 276
## Number of parameters estimated: 6
## AIC: -161.06, (AIC for lm: -161.11)
## LM test for residual autocorrelation
## test value: 3.1563, p-value: 0.075633
## Pooling SEM pelo pacote 'spdep'
sempool.2 <- errorsarlm(formula = fm, data = cigar, listw = pool.lwcig)
summary(sempool.2)
##
## Call:errorsarlm(formula = fm, data = cigar, listw = pool.lwcig)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.5998877 -0.0916386 -0.0081973 0.0740753 0.6904247
##
## Type: error
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 1.484185 0.312829 4.7444 2.091e-06
## logp -1.060385 0.118173 -8.9732 < 2.2e-16
## logpn 0.150483 0.125306 1.2009 0.2298
## logy 0.730092 0.069817 10.4572 < 2.2e-16
##
## Lambda: 0.14756, LR test value: 4.6572, p-value: 0.030924
## Asymptotic standard error: 0.076541
## z-value: 1.9278, p-value: 0.053882
## Wald statistic: 3.7163, p-value: 0.053882
##
## Log likelihood: 87.88319 for error model
## ML residual variance (sigma squared): 0.030797, (sigma: 0.17549)
## Number of observations: 276
## Number of parameters estimated: 6
## AIC: -163.77, (AIC for lm: -161.11)
Referências
Baltagi, Badi H, Seuck Heun Song, and Won Koh. 2003. “Testing Panel Data Regression Models with Spatial Error Correlation.” Journal of Econometrics 117 (1). Elsevier: 123–50.
Millo, Giovanni, and Gianfranco Piras. 2012. “splm: Spatial Panel Data Models in R.” Journal of Statistical Software 47 (1): 1–38. http://www.jstatsoft.org/v47/i01/.
Rasmussen, Poul Nørregaard. 2003. Econometric Analysis of Panel Data. John Wiley; Sons. http://www.wiley.com/legacy/wileychi/baltagi/.