Skip to content

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

@shuai-zhou

Description

@shuai-zhou

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions