You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R语言报错求助:Lapack routine dgesv系统精确奇异U[10,10]=0

Troubleshooting the "Lapack routine dgesv: system is exactly singular" Error in pgmm()

Hey there, let's break down why you're hitting this error and walk through practical fixes to get your GMM estimation working.

Why This Error Happens

This error means the matrix the estimation routine is trying to invert is singular (it has no inverse), which usually stems from one or more of these issues with your setup:

  • Too few cross-sectional units: You only have 4 countries, which is a very small sample for GMM. GMM relies on having enough variation across units to estimate the moment conditions, and small N can lead to underdetermined systems where the matrix can't be inverted.
  • Overloaded set of instruments/regressors: Your model includes a lot of terms (lags of log(y2), EU_IM, Non_EU_IM, plus log(GDP)), and the gmm.inst argument adds even more instruments from lags of log(y2). When the number of instruments or regressors approaches (or exceeds) the effective number of observations, the matrix becomes singular.
  • Perfect multicollinearity: Some of your regressors might be perfectly linearly related. For example, maybe EU_IM and Non_EU_IM (or their lags) are perfectly correlated, or a lagged term is a linear combination of other variables in the model.
  • Zero-variance variables: If any variable in your model has no variation (e.g., one country's EU_IM is the same every quarter), this will also cause the matrix to lose rank and become singular.

Fixes to Try

Here are targeted steps to resolve the issue:

  • Trim your instrument set: Reduce the number of instruments by tightening the lag.gmm specification. Instead of using lags 2 and 3 of log(y2) as instruments, try a narrower range like lag.gmm = list(c(2,2)) (only the 2nd lag). For small N, fewer instruments mean a more stable matrix.
  • Simplify your model: Drop regressors that aren't theoretically necessary or show low explanatory power. Start with a parsimonious version (e.g., only include 1 lag of log(y2), current EU_IM/Non_EU_IM, and log(GDP)), then add terms one by one to see which is causing the singularity.
  • Check for multicollinearity: Run cor(df[, c("log(y2)", "EU_IM", "Non_EU_IM", "log(GDP)")]) to spot variables with near-perfect correlation (correlation coefficient close to ±1). If you find any, remove one of the correlated variables or combine them (e.g., total imports instead of splitting into EU/Non-EU).
  • Validate your data: Use summary(df) to check for variables with zero variance. If you find any, either drop that variable or check if there's a data entry error causing the lack of variation.
  • Try the two-step GMM: Switch to model = "twostep" instead of "onestep". The two-step routine uses a different weight matrix calculation that might be more robust to small samples (though you should still address instrument/regressor bloat first).

内容的提问来源于stack exchange,提问作者R.M

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:49:57