System is computationally singular: reciprocal condition number in R
Two fundamental linear algebra properties:
- A singular (square) matrix is a (square) matrix that is not invertible.
- A matrix is not invertible if its determinant equals zero.
If you check
set.seed(2018);
x <- matrix(rnorm(80, mean = 0, sd = 0.1), 8, 8)
c <- cov(x)
det(c)
#[1] -3.109158e-38
So indeed, det(c)
is zero (within machine precision); hence c
is not invertible, which is exactly what solve(c)
is trying to do.
PS 1: Take a look at ?solve
to see that solve(a)
will return the inverse of a
.
PS 2: There exists a nice post on Mathematics on the interpretation of the determinant of the covariance matrix. Take a look to understand why you're seeing what you're seeing.
Error system is computationally singular when trying to run panel data regression
Changing the unit as a workaround solved the problem.
Mahalonobis distance in R, error: system is computationally singular
The Mahalanobis distance requires you to calculate the inverse of the covariance matrix. The function mahalanobis
internally uses solve
which is a numerical way to calculate the inverse. Unfortunately, if some of the numbers used in the inverse calculation are very small, it assumes that they are zero, leading to the assumption that it is a singular matrix. This is why it specifies that they are computationally singular, because the matrix might not be singular given a different tolerance.
The solution is to set the tolerance for when it assumes that they are zero. Fortunately, mahalanobis
allows you to pass this parameter (tol
) to solve
:
mahalanobis(dat,center=centroid,cov=cov(dat),tol=1e-20)
# [1] 24.215494 28.394913 6.984101 28.004975 11.095357 14.401967 ...
Can you use a reciprocal condition when getting Error in solve.default when using svychisq
Thank you so much for the answers. After running the table I realized the issue was that the responses weren't evenly distributed. So, I recoded the outcomes to only those I wanted, throwing the rest into an "other" category and that worked!
Related Topics
Finding the Index of First Changes in the Elements of a Vector
How to Force Seasonality from Auto.Arima
Find the Nearest X,Y Coordinate Using R
Compute Only Diagonals of Matrix Multiplication in R
Split Data.Frame into Groups by Column Name
Understanding Lm and Environment
R Looping Through in Survey Package
How to Turn the Filename into a Variable When Reading Multiple CSVS into R
How to Tell Which Packages I am Not Using in My R Script
Get Continent Name from Country Name in R
Custom Ggplot2 Axis and Label Formatting
How to Get a List of All Possible Partitions of a Vector in R
Height' Must Be a Vector or a Matrix. Barplot Error
From [Package] Import [Function] in R