A similar issue can be found here, but I did not understand what @gboeing meant by adding noise to dummy variables. Anyway, I got the "Singular matrix" error when implementing random effect spatial error model using spreg.Panel_RE_Error. The test data can be downloaded here, it is a longitudinal data in long format. And my code looks like the following:
# Load libraries
import numpy as np
import pandas as pd
import geopandas as gpd
import libpysal
from pysal.lib import weights
from pysal.model import spreg
# Read data
zipfile = './data/model_test.zip'
gdf = gpd.read_file(zipfile)
# Construct weight
w = weights.Queen.from_dataframe(gdf.iloc[0:254, :])
w.transform = 'r'
# Prepare variables
y = gdf[['y']]
x = gdf[['colle', 'labor', 'year_1980', 'year_1990']]
# Model fitting. This step throws singular matrix error
re_error = spreg.Panel_RE_Error(y.to_numpy(),
x.to_numpy(),
w,
name_y=list(y.columns),
name_x=list(x.columns))
print(re_error.summary)
What caused the singular matrix issue in this context and how can I fix it? Thanks.
A similar issue can be found here, but I did not understand what @gboeing meant by adding noise to dummy variables. Anyway, I got the "Singular matrix" error when implementing random effect spatial error model using
spreg.Panel_RE_Error
. The test data can be downloaded here, it is a longitudinal data in long format. And my code looks like the following:What caused the singular matrix issue in this context and how can I fix it? Thanks.