6
$\begingroup$

I am currently trying to estimate some panel data models in R using PLM package. This includes the estimation of basic pooled, fixed effects and random effects models. Therefore I make use of this code:

# read in data
mydata<- read.csv2("Panel.csv")
attach(mydata)

# define dependant variable
standarddeviation <- cbind(sd)
# define independant variable
x <- cbind(ratio1, ratio2, ratio3, ratio4, mean)

# Set data as panel data
pdata <- plm.data(mydata, index=c("id","t"))

# Pooled OLS estimator
pooling <- plm(standarddeviation ~ x, data=pdata, model= "pooling")
summary(pooling)

# Between estimator
between <- plm(standarddeviation ~ x, data=pdata, model= "between")
summary(between)

# First differences estimator
firstdiff <- plm(standarddeviation ~ x, data=pdata, model= "fd")
summary(firstdiff)

# Fixed effects or within estimator
fixed <- plm(standarddeviation ~ x data=pdata, model= "within")
summary(fixed)

# Random effects estimator
random <- plm(standarddeviation ~ x, data=pdata, model= "random")
summary(random)

Now here's the problem: I can without any problem estimate all models except for the random effects model. After entering the "random"-formula, R produces the following error:

"Error in solve.default(crossprod(X.m)) : 
  system is computationally singular: reciprocal condition number = 9.57127e-023"

First guesses:

  • Linear combinations in x? A first guess would be that there are exact linear dependencies of the exogenous variables in x. The data is balance sheet data and I would like to explain the standard deviation (y) of a specific balance sheet position by other balance sheet positions (or the ratio of the position and the balance sheet sum). Of course, the variables in x are related to each other. For example some of the ratios are calculated by dividing by the mean which is also a separate independant variable. And the dependant variable, which is the standard deviation, is also calculated by using this mean. But again: There should be no EXACT correlation. But: If I exclude some of my exogenous variables, the problem disappears, but I have to include them actually.
  • Unbalanced panel / NAs? The data is unbalanced and there are NAs. Fixed effects output says: n=16, T=18-40, N=455. Probably the unbalanced data or the NAs are the reason for the error?

Traceback-Code:

random <- plm(standarddeviaution ~ x, data=pdata, model= "random")
Error in solve.default(crossprod(X.m)) : 
  system is computationally singular: reciprocal condition number = 9.57127e-023
traceback()
8: solve.default(crossprod(X.m))
7: solve(crossprod(X.m))
6: diag(solve(crossprod(X.m)) %*% crossprod(X.sum))
5: swar(object, data, effect)
4: ercomp.formula(formula, data, effect, method = random.method)
3: ercomp(formula, data, effect, method = random.method)
2: plm.fit(formula, data, model, effect, random.method, inst.method)
1: plm(standarddeviation ~ x, data = pdata, model = "random")

Is there anybody who can give me a hint what this error does actually mean and especially: how to solve the problem? How do I have to correct the code in order to get results? Thanks a lot!

$\endgroup$
2
  • 1
    $\begingroup$ I have the same problem. I saw here that it maybe due to high correlation among the dependent vars, but that did not fix my problem. Did you ever get around this problem? When I run the same data set and the same model in STATA, my random effects model actually works. Its only R that produces this error. $\endgroup$
    – user49017
    Commented Aug 24, 2015 at 22:25
  • $\begingroup$ Can you make the data available? $\endgroup$
    – Helix123
    Commented Mar 30, 2017 at 11:11

3 Answers 3

5
$\begingroup$

Caveat: I haven't used the plm package.

It's impossible to recreate this error because we don't have access to your data. But if the matrix is computationally singular, then you have a problem of multicollonearity. As you've identified, there's essentially two reasons that can happen.

  1. Multicollinearity. Even if the pairwise correlations are low, it's possible that more than two columns of IVs are highly collinear with another IV column. Another piece of evidence toward this conclusion is that excluding some variables removes the error: you're removing some of the collinear columns, so the estimators are uniquely identifiable given the available data. Removing highly collinear columns doesn't change the amount of information to the regression -- the removed variables are completely or mostly determined by the remaining ones -- so it's perfectly valid as a solution. It's purely a question which explanatory variables you are more interested in.

  2. More features than observations You speculate that this could be problem with this remark.

Unbalanced panel / NAs? The data is unbalanced and there are NAs. Fixed effects output says: n=16, T=18-40, N=455. Probably the unbalanced data or the NAs are the reason for the error?

I don't know what "n=16, T=18-40, N=455" means to you (What are n, T, and N?). But a regression with more columns than observations is likewise not identified by the data.

$\endgroup$
0
$\begingroup$

I had the same problem (see this question), and actually I haven't found yet a solution I am happy with, but I can give you a hint about the cause of the error and how to work around it.

As reported here, the problem is related to the fact that R approximates with zero extremely low values (in your case 1e-023). When it computes the inverse of a matrix, the mistakenly reported zeros make the model say that the matrix is singular, actually computationally singular. That's the reason why Stata correctly processes your data, it has just a larger tolerance before approximating very small quantities with zero.

I worked around the problem by changing the random.method settings from "swar", the default one, to "walhus". This solves the computational problems and makes the model run. Whether this is statistically a desirable option is up to you to decide.

Hope this helps.

$\endgroup$
1
  • 1
    $\begingroup$ You’re describing floating point round off error. This isn’t unique to R, but an inherent problem with floating point numbers — they’re just an approximation to real numbers, so some operations with specific data are imprecise. Likewise, R implements integers, which do not have roundoff error (but are only exact within a specific range). $\endgroup$
    – Sycorax
    Commented Aug 14, 2022 at 21:17
-1
$\begingroup$

I tried all the possible options in random.method, but I still got the same message -

Error in solve.default(vcov(x)[names.coefs_wo_int, names.coefs_wo_int],  : 
system is computationally singular: reciprocal condition number = 9.29205e-18

The reciprocal condition number changes for the different options.

However, when I log transformed one of the variables, the issue didn't occur.

Edited: Aug 20, 2022 - I think this is because of degrees of freedom issues and also STATA can model such a case but R's current package is unable to.

$\endgroup$
8
  • 3
    $\begingroup$ It might help to elaborate on why this was, & when it could be appropriate $\endgroup$
    – Scortchi
    Commented Aug 14, 2022 at 22:39
  • $\begingroup$ @Scortchi-ReinstateMonica - I myself don't know the reason, I just shared the output after trying the approach suggested in the earlier comments. If I am able to identify the reason, I will surely update! $\endgroup$ Commented Aug 16, 2022 at 9:25
  • 1
    $\begingroup$ Your variable was linearly dependent on the others. The log transformation, being nonlinear, would likely cure that problem. This indeed is a possible solution to the original problem, but (absent access to the data) there's no way to tell. $\endgroup$
    – whuber
    Commented Aug 16, 2022 at 13:00
  • $\begingroup$ @whuber - Thanks. The correlation of the raw and log form are very less with other variables. The VIF is also less than 4 for all. Seems something else is the reason. I am also trying to find. $\endgroup$ Commented Aug 17, 2022 at 14:30
  • 1
    $\begingroup$ In the case you describe, that is not so, for the reasons I have given. The entire linear structure of all your explanatory variables matters, of course--but a single correlation coefficient is no substitute for that information. $\endgroup$
    – whuber
    Commented Aug 18, 2022 at 16:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.