Eigen: Eigenanalysis preserving dimnames

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/Eigen.R

Description

Compute eigenvalues and vectors, assigning names to the eigenvalues and dimnames to the eigenvectors.

Usage

1
2
Eigen(x, symmetric, only.values = FALSE, 
      valuenames )

Arguments

x

a square matrix whose spectral decomposition is to be computed.

symmetric

logical: If TRUE, the matrix is assumed to be symmetric (or Hermitian if complex) and only its lower triangle (diagonal included) is used. If 'symmetric' is not specified, the matrix is inspected for symmetry.

only.values

if 'TRUE', only the eigenvalues are computed and returned, otherwise both eigenvalues and eigenvectors are returned.

valuenames

character vector of length nrow(x) or a character string that can be extended to that length by appening 1:nrow(x).

The default depends on symmetric and whether rownames == colnames: If rownames == colnames and symmetric = TRUE (either specified or determined by inspection), the default is "paste('ev', 1:nrow(x), sep=”)". Otherwise, the default is colnames(x) unless this is NULL.

Details

1. Check 'symmetric'

2. ev <- eigen(x, symmetric, only.values = FALSE); see eigen for more details.

3. rNames = rownames(x); if this is NULL, rNames = if(symmetric) paste('x', 1:nrow(x), sep=”) else paste('xcol', 1:nrow(x)).

4. Parse 'valuenames', assign to names(ev[['values']]).

5. dimnames(ev[['vectors']]) <- list(rNames, valuenames)

NOTE: This naming convention is fairly obvious if 'x' is symmetric. Otherwise, dimensional analysis suggests problems with almost any naming convention. To see this, consider the following simple example:

X <- matrix(1:4, 2, dimnames=list(LETTERS[1:2], letters[3:4]))

c d
A 1 3
B 2 4

X.inv <- solve(X)

A B
c -2 1.5
d 1 -0.5

One way of interpreting this is to assume that colnames are really reciprocals of the units. Thus, in this example, X[1,1] is in units of 'A/c' and X.inv[1,1] is in units of 'c/A'. This would make any matrix with the same row and column names potentially dimensionless. Since eigenvalues are essentially the diagonal of a diagonal matrix, this would mean that eigenvalues are dimensionless, and their names are merely placeholders.

Value

a list with components values and (if only.values = FALSE) vectors, as described in eigen.

Author(s)

Spencer Graves

See Also

eigen, svd qr chol

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
X <- matrix(1:4, 2, dimnames=list(LETTERS[1:2], letters[3:4]))
eigen(X)
Eigen(X)
Eigen(X, valuenames='eigval')

Y <- matrix(1:4, 2, dimnames=list(letters[5:6], letters[5:6]))
Eigen(Y)

Eigen(Y, symmetric=TRUE)
# only the lower triangle is used;
# the upper triangle is ignored.  

Example output

Loading required package: splines
Loading required package: Matrix
Loading required package: fds
Loading required package: rainbow
Loading required package: MASS
Loading required package: pcaPP
Loading required package: RCurl

Attaching package:fdaThe following object is masked frompackage:graphics:

    matplot

eigen() decomposition
$values
[1]  5.3722813 -0.3722813

$vectors
           [,1]       [,2]
[1,] -0.5657675 -0.9093767
[2,] -0.8245648  0.4159736

eigen() decomposition
$values
         c          d 
 5.3722813 -0.3722813 

$vectors
           c          d
A -0.5657675 -0.9093767
B -0.8245648  0.4159736

eigen() decomposition
$values
   eigval1    eigval2 
 5.3722813 -0.3722813 

$vectors
     eigval1    eigval2
A -0.5657675 -0.9093767
B -0.8245648  0.4159736

eigen() decomposition
$values
         e          f 
 5.3722813 -0.3722813 

$vectors
           e          f
e -0.5657675 -0.9093767
f -0.8245648  0.4159736

eigen() decomposition
$values
ev1 ev2 
  5   0 

$vectors
        ev1        ev2
e 0.4472136 -0.8944272
f 0.8944272  0.4472136

fda documentation built on May 2, 2019, 5:12 p.m.