R inverting matrix with solve returning Error

Juneyoung Oh picture Juneyoung Oh · May 23, 2015 · Viewed 9.6k times · Source

I am studying R programming.

I am trying to inverting matrix. Below is what I have tried.

x <- matrix(1:16, 4, 4)
x
#      [,1] [,2] [,3] [,4]
# [1,]    1    5    9   13
# [2,]    2    6   10   14
# [3,]    3    7   11   15
# [4,]    4    8   12   16

solve(x)
# Error in solve.default(x) : 
#  Lapack routine dgesv: system is exactly singular: U[3,3] = 0

solve(x) %*% x
# Error in solve.default(x) : 
#  Lapack routine dgesv: system is exactly singular: U[3,3] = 0

x %*% solve(x)
# Error in solve.default(x) : 
#  Lapack routine dgesv: system is exactly singular: U[3,3] = 0

I can not understand what 'singular' means. According to this link, it is said that if solve does not have second parameter, it inverts first parameter.

I am fully confused, so need some explanation with example would be wonderful.

Answer

Colonel Beauvel picture Colonel Beauvel · May 23, 2015

If you compute the determinant of the matrix, it is 0:

det(x)
[1] 0

By definition, your matrix is not invertible. But before trying to invert a squared matrix, the first instinct should be to study analytically if the matrix can be invertible.

The singular error you get just reflects the matrix is not invertible.