firstpos: ensures that the first element of all the columns of one/two...

View source: R/firstpos.R

firstposR Documentation

ensures that the first element of all the columns of one/two matrix/matrices is positive.

Description

firspos: Changes the sign of the values of the columns in one or two matrices according to the sign of the elements in the first line of the first matrix. After transformation the first element of every column of the matrix or matrices will be positive.

This is used to get reproducible results when performing singular value decompositions or eigenvalue decompositions.

Note that when provided two matrices the signs of the matrices will match: This is used to ensure that the sign of the singular vectors of a given matrix match.

Usage

firstpos(P, Q = NULL)

Arguments

P

A matrix of numeric values

Q

If not NULL, a matrix of numeric values with the same number of columns as P

Value

If Q is NULL, then the function returns only the modified P matrix. Otherwise, the function returns a list with two elements:

  • P A matrix with the same values as in P, except that the sign of all the values in each column is flipped if the first value of this column is negative.

  • Q A matrix with the same values as in Q, except that the sign of all the values in each column is flipped the same way that it is flipped forP.

Author(s)

Vincent Guillemot and Hervé Abdi

See Also

firstpos4ExPo, renormInertiaExPo

Examples

## Not run: 
 A <- matrix(rnorm(4), 2, 2)
 B <- matrix(rnorm(6), 3, 2)
 firstpos(A, B)

## End(Not run)

HerveAbdi/data4PCCAR documentation built on July 20, 2024, 7:52 a.m.