针对面板数据运行空间杜宾模型 (SDM)

问题描述 投票:0回答:1

我正在尝试为空间面板数据运行空间杜宾模型。我的想法是在自变量

y
x1
上运行因变量
x2
。我尝试了很多选项,但它们都给我错误。以下是我尝试的前 2 个选项所遵循的步骤:

library("sf")
library("dplyr")
library("spdep")
library("spatialreg")
library("spmodel")
library(plm)
library(GWPR.light)
library(sp)
library(GWmodel)
library(spgwr)
library(SDPDmod)


#Deleting the observations that don't have information for my regression variables y, x1, and x2:
test <- DataTest_shp %>% dplyr::filter(across(c(y , x1,x2),~ !is.na(.)))  

#Creating weight matrix:
shapefile_centroid <- sf::st_centroid(test) 
coordsW   <- test  %>%  st_centroid()%>% st_geometry() 
nb.d125<- dnearneigh(coordsW,0,125000,row.names=coordsW$ID)
mat.d125 <-nb2mat(nb.d125,glist=NULL,style="W",zero.policy=TRUE)
listd125 = mat2listw(mat.d125, style="W")
  
#Running the regression:
formula.GWPR <- y ~ x1+x2
#1st Option for running the regression:
res3<-blmpSDPD(formula.GWPR, 
               data   = test, 
               W      = mat.d125,
               index  = c("ID","year"),
               model  = list("sdm"), 
               effect = "twoways",
               prior  = "beta")

第一个选项错误:

Error in blmpSDPD(formula.GWPR, data = test, W = mat.d125, index = c("ID",  : 
  Non conformable spatial weights
#2nd Option for running the regression:
mod5<-SDPDm(formula.GWPR, data = test, 
            W = mat.d125,
            index = c("ID","year"),
            model = "sdm", 
            effect = "twoways",
            LYtrans = T,
            dynamic = T,
            tlaginfo = list(ind = NULL, tl = T, stl = T))

第二个选项错误:

Error in xtfrm.data.frame(x) : cannot xtfrm data frames

提前非常感谢!

请在此处

查找可用数据
r panel-data spatial-regression
1个回答
0
投票

我意识到我的错误是我的数据和权重矩阵中有不同数量的观察值。 我通过保持数据集的观察数量与 shapefile 中存在的数量相同来解决这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.