Download Multivariate statistical functions in R

Document related concepts

Linear least squares (mathematics) wikipedia , lookup

Bootstrapping (statistics) wikipedia , lookup

Degrees of freedom (statistics) wikipedia , lookup

Student's t-test wikipedia , lookup

Transcript
4 Some other multivariate functions
In this section we show some other functions for multivariate data, such as standardization,
a simple normality test and some other functions.
4.1 Distributional related functions
4.1.1
Standardization I
This is probably the transformation to which the term suits better. This function transforms
the data such that they have zero mean vector and the identity as the covariance matrix. We
used this function to perform hypothesis testing for zero correlation using bootstrap but did
not pay too much attention. At first we have to subtract the mean vector from the data and
then multiply by the square root of the inverse of the covariance matrix
Z = (X − µ ) Σ −1/2 .
The key thing is to decompose the covariance matrix, using Cholesky or eigen decomposition. We prefer the latter for simplicity and convenience. The spectral decomposition of the
covariance matrix (or any square matrix in general) is
Λ V T = Vdiag λ1 , . . . , λ p V T ,
Σ = VΛ
where V is the matrix containing the eigenvectors, an orthogonal matrix and λ1 , . . . , λ p are
the p eigenvalues (the number of dimensions), where λ1 ≥ λ2 ≥ . . . ≥ λ p > 0. The inverse
of Σ and its square root can be written as
−1/2
1
T
−1/2
−1/2
Σ −1 = Vdiag λ1−1 , . . . , λ−
V
and
Σ
=
Vdiag
λ
,
.
.
.
,
λ
V T respectively.
p
p
1
If the covariance matrix is not of full rank (equal to p), that is if there is at least one eigenvalue
equal to zero, it becomes clear why the inverse does not exist. Another thing to highlight is
that the number of non zero eigenvalues is equal to the rank of the matrix (or vice versa). The
following function performs this transformation using eigen decomposition of the covariance
matrix.
multivzscore=function(x) {
## x contains the data
x=as.matrix(x)
n=nrow(x) ; s=cov(x) ; p=ncol(x)
m=matrix(rep(colMeans(x),n),byrow=TRUE,ncol=p)
lam=eigen(s)$values
vec=eigen(s)$vectors
47