spatial panel regression in R: non conformable spatial weights?

Viewed 1399

I am trying to run a spatial panel regression in R with the splm package. So I have polygons with summarized data over time and I want to see how the dependent variable is affected by the other variables that also change over time.

I have 546 regions with a number of variables, but to test how it works I took a subset of my data for 3 polygons, including the shapefile for calculating the weights, and the data.

https://drive.google.com/file/d/0B4SK0f2zZUKxZ0dDU2lnclB2M3c/view?usp=sharing

#load data
file="sector_panel_data_test.csv"
sector_data=read.table(file,sep=",", header=T, quote="")
sector_data[is.na(sector_data)] <- 0
names(sector_data)
attach(sector_data)

#load shape
require (rgdal)
sectors <-readOGR(dsn=".",layer="sectors_test_sample_year1")
nb <- poly2nb(sectors)


#distance based neighbors
coords <- coordinates(sectors)
nb.d125<- dnearneigh(coords,0,125000,row.names=sectors$Code)

#create weights matrix
mat.d125 <-nb2mat(nb.d125,glist=NULL,style="W",zero.policy=TRUE)

#and then a weights list object
listd125 = mat2listw(mat.d125, style="W")

#design model and run, just picked one variable here
fm <- prop_fdeg ~ mean_pop
randommodel <-spml(fm, 
data=sector_data,index=NULL,listw=listFQQ,model="random", lag=FALSE)

I get the following error:

Error in spreml(formula = formula, data = data, index = index, w = listw2mat(listw), : Non conformable spatial weights

Does anyone know what this means? I have searched everywhere, and only found people with the same problem looking for a solution.

3 Answers

This might not be relevant to your problem, but hopefully can help others searching for this error.

Data have to be in specific format: first two columns containing index and time in this order and rest is remaining variables. Switching time and index will cause Non conformable spatial weights because dim(w) != n, where $n$ will be number of unique elements of time.

I had the same problem myself.

It turned out that my spatial weight matrix contained one extra country.

For e.g., your dataset contains 33 countries, but you have a matrix of 34 countries.

Simply remove that extra country from the matrix

Related