Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

random effect spatial error model encounters "LinAlgError: Singular matrix" error #87

Open
shuai-zhou opened this issue Feb 17, 2022 · 2 comments

Comments

@shuai-zhou
Copy link

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.

@ljwolf
Copy link
Member

ljwolf commented Feb 28, 2022

This is usually caused by perfect collinearity in your x matrix.... I'll try to have a look this week.

@shuai-zhou
Copy link
Author

@ljwolf Thanks, I am looking forward to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants