Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"system is computationally singular" error when using `gmm` (GMM Estimation)

Tags:

r

Trying to use the GMM package in R to estimate the parameters (a-f) of a linear model:

LEV1 = a*Macro + b*Firm + c*Sector + d*qtr + e*fqtr + f*tax

Macro, Firm and Sector are matrices with n number of rows. qtr, fqtr and tax are vectors with n members.

I have one large data frame called unconstrd that has all of the data. First, I break that data into separate matrices:

v_LEV1 <- as.matrix(unconstrd$LEV1)
Macro <- as.matrix(cbind(unconstrd$Agg_Corp_Prof,unconstrd$R1000_TR, unconstrd$CP_Spread))
Firm <- as.matrix(cbind(unconstrd$ppe_ratio, unconstrd$op_inc_ratio_avg, unconstrd$selling_exp_avg,
                  unconstrd$tax_avg, unconstrd$Mark_to_Bk, unconstrd$mc_ratio))
Sector <- as.matrix(cbind(unconstrd$Sect_Flag03,
                  unconstrd$Sect_Flag04, unconstrd$Sect_Flag05, unconstrd$Sect_Flag06,
                  unconstrd$Sect_Flag07, unconstrd$Sect_Flag08, unconstrd$Sect_Flag12,
                  unconstrd$Sect_Flag13, unconstrd$Sect_Flag14, unconstrd$Sect_Flag15,
                  unconstrd$Sect_Flag17))
v_qtr <- as.matrix(unconstrd$qtr)
v_fqtr <- as.matrix(unconstrd$fqtr)
v_tax <- as.matrix(unconstrd$tax_dummy)

Then, I bind the data together for the x variable called by gmm:

h=cbind(Macro,Firm,Sector,v_qtr, v_fqtr, v_tax)

Then, I invoke gmm:

gmm1 <- gmm(v_LEV1 ~ Macro + Firm + Sector + v_qtr + v_fqtr + v_tax, x=h)

I get the message:

Error in solve.default(crossprod(hm, xm), crossprod(hm, ym)) : 
  system is computationally singular: reciprocal condition number = 1.10214e-18

I apologize in advance and admit that I'm a neophyte at R and I've never used GMM before. The GMM function is so general, I've looked at the examples available on the web but nothing seems specific enough to help my situation.

like image 796
eqsf Avatar asked Jan 04 '13 20:01

eqsf


2 Answers

You are trying to fit onto a matrix which does not have full rank---try excluding some of the variable and/or look for errors. We cannot say much more without your data, or at least a sample.

That's more of a modelling question for Crossvalidated.com than a programming question for StackOverflow.

like image 124
Dirk Eddelbuettel Avatar answered Nov 03 '22 01:11

Dirk Eddelbuettel


I was pretty certain there was no linear dependency between my variables but I went through the exercise of adding one variable at a time to see what was causing the errors. In the end, I asked a colleague to run GMM on SAS and it ran perfectly, no error messages. I'm not sure what the problem is with the R version is but at this point I have a solution and give u on GMM on R.

Thanks to everyone who tried to help.

like image 37
eqsf Avatar answered Nov 03 '22 01:11

eqsf