Given a matrix of less than full rank, the conventional inverse function will fail. The pseudoinverse or generalized inverse resolves this problem by using just the postive values of the singular value decomposition d matrix. An adaptation of the ginv function from MASS and the pinv function from pracma.

Pinv(X, tol = sqrt(.Machine$double.eps))

Arguments

X

A correlation or covariance matrix to analyze

tol

A very small number. Reject values with eigen values less than tolerance

Details

The singular value decomposition of a matrix X is UdV where for full rank matrices, d is the vector of eigen values and U and V are the matrices of eigen vectors. The inverse is just U/d. If the matrix is less than full rank, many of the d values are effectively zero (at the limit of computational accuracy.) Thus, to solve matrix equations with matrices of less than full rank (e.g. the schmid Schmid-Leiman solution), we need to find the generalized inverse.

Value

The generalized inverse

References

Venables, W. N. and Ripley, B. D. (1999) Modern Applied Statistics with S-PLUS. Third Edition. Springer. p.100.

Author

William Revelle

Note

Adapted from the ginv function in MASS and the pinv function in pracma. Installed here to avoid loading those packages.

See also

Examples

round(Pinv(Thurstone) %*% Thurstone,2)  #an identity matrix
#>       Sentences Vocabulary Sent.Completion First.Letters Four.Letter.Words
#>  [1,]         1          0               0             0                 0
#>  [2,]         0          1               0             0                 0
#>  [3,]         0          0               1             0                 0
#>  [4,]         0          0               0             1                 0
#>  [5,]         0          0               0             0                 1
#>  [6,]         0          0               0             0                 0
#>  [7,]         0          0               0             0                 0
#>  [8,]         0          0               0             0                 0
#>  [9,]         0          0               0             0                 0
#>       Suffixes Letter.Series Pedigrees Letter.Group
#>  [1,]        0             0         0            0
#>  [2,]        0             0         0            0
#>  [3,]        0             0         0            0
#>  [4,]        0             0         0            0
#>  [5,]        0             0         0            0
#>  [6,]        1             0         0            0
#>  [7,]        0             1         0            0
#>  [8,]        0             0         1            0
#>  [9,]        0             0         0            1
if(!require(GPArotation)) {
   message("I am sorry, you must have GPArotation installed to use schmid.")} else  {
        sl <- schmid(Thurstone,3)  #The schmid-leiman solution is less than full rank
F <- sl$sl[,1:4]    #the SL solution is general + 3 groups
R <- Thurstone      #
diag(R) <- sl$sl[,5]  #the reproduced matrix (R - U2)
S <- t(Pinv(t(F) %*% F) %*% t(F) %*% R)  #the structure matrix
Phi <- t(S) %*%  F %*% Pinv(t(F) %*% F)  #the factor covariances
}
#> Loading required package: GPArotation
#> 
#> Attaching package: ‘GPArotation’
#> The following objects are masked from ‘package:psych’:
#> 
#>     equamax, varimin