Last data update: 2014.03.03

R: Validates the specified correlation matrix
validation.corrR Documentation

Validates the specified correlation matrix

Description

This function validates the specified correlation vector and/or matrix for appropriate dimension, symmetry, range, and positive definiteness. If both correlation matrix and correlation vector were supplied, it checks whether the matrix and vector are conformable.

Usage

validation.corr(n.BB, n.NN, corr.vec = NULL, corr.mat = NULL)

Arguments

n.BB

Number of binary variables.

n.NN

Number of continuous non-normal variables.

corr.vec

Vector of elements below the diagonal of correlation matrix ordered columnwise.

corr.mat

Specified correlation matrix.

Value

The function returns TRUE if no specification problem is encountered. Otherwise, it returns an error message.

See Also

correlation.limits, correlation.bound.check

Examples

n.BB=2
n.NN=4
corr.vec=NULL
corr.mat=matrix(c(1.0,-0.3,-0.3,-0.3,-0.3,-0.3,
-0.3,1.0,-0.3,-0.3,-0.3,-0.3,
-0.3,-0.3,1.0,0.4,0.5,0.6,
-0.3,-0.3,0.4,1.0,0.7,0.8,
-0.3,-0.3,0.5,0.7,1.0,0.9,
-0.3,-0.3,0.6,0.8,0.9,1.0),6,byrow=TRUE)

validation.corr(n.BB,n.NN,corr.vec=NULL,corr.mat)

n.BB=2
n.NN=4
corr.vec=c(-0.3,-0.3,-0.3,-0.3,-0.3,-0.3,-0.3,-0.3,-0.3,0.4,0.5,0.6,0.7,0.8,0.9)
validation.corr(n.BB,n.NN,corr.vec,corr.mat=NULL)

## Not run: 
n.BB=0
n.NN=4
validation.corr(n.BB,n.NN,corr.vec=NULL,corr.mat)

n.BB=2
n.NN=0
validation.corr(n.BB,n.NN=0,corr.vec=NULL,corr.mat)

corr.matc=corr.mat[3:6,3:6]
validation.corr(n.BB=0,n.NN=4,corr.vec=NULL,corr.mat=corr.matc)

corr.mat[2,1]=0.5
validation.corr(n.BB,n.NN,corr.vec=NULL,corr.mat)

corr.mat[1,2]=0.5
corr.mat[3,1]=1.5
corr.mat[1,3]=1.5
validation.corr(n.BB,n.NN,corr.vec=NULL,corr.mat)

npd<-matrix(c(1,     0.477, 0.644, 0.478, 0.651, 0.826,
               0.477, 1,     0.516, 0.233, 0.682, 0.75,
               0.644, 0.516, 1,     0.599, 0.581, 0.742,
               0.478, 0.233, 0.599, 1,     0.741, 0.8,
               0.651, 0.682, 0.581, 0.741, 1,     0.798,
               0.826, 0.75,  0.742, 0.8,   0.798, 1),
               nrow = 6, ncol = 6)

validation.corr(n.BB,n.NN,corr.vec=NULL,corr.mat=npd)

n.BB=1
n.NN=0
corr.mat<-diag(1)
validation.corr(n.BB,n.NN,corr.vec=NULL,corr.mat)


## End(Not run)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(BinNonNor)
Loading required package: BB
Loading required package: corpcor
Loading required package: mvtnorm
Loading required package: Matrix
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/BinNonNor/validation.corr.Rd_%03d_medium.png", width=480, height=480)
> ### Name: validation.corr
> ### Title: Validates the specified correlation matrix
> ### Aliases: validation.corr
> 
> ### ** Examples
> 
> n.BB=2
> n.NN=4
> corr.vec=NULL
> corr.mat=matrix(c(1.0,-0.3,-0.3,-0.3,-0.3,-0.3,
+ -0.3,1.0,-0.3,-0.3,-0.3,-0.3,
+ -0.3,-0.3,1.0,0.4,0.5,0.6,
+ -0.3,-0.3,0.4,1.0,0.7,0.8,
+ -0.3,-0.3,0.5,0.7,1.0,0.9,
+ -0.3,-0.3,0.6,0.8,0.9,1.0),6,byrow=TRUE)
> 
> validation.corr(n.BB,n.NN,corr.vec=NULL,corr.mat)
[1] TRUE
> 
> n.BB=2
> n.NN=4
> corr.vec=c(-0.3,-0.3,-0.3,-0.3,-0.3,-0.3,-0.3,-0.3,-0.3,0.4,0.5,0.6,0.7,0.8,0.9)
> validation.corr(n.BB,n.NN,corr.vec,corr.mat=NULL)
[1] TRUE
> 
> ## Not run: 
> ##D n.BB=0
> ##D n.NN=4
> ##D validation.corr(n.BB,n.NN,corr.vec=NULL,corr.mat)
> ##D 
> ##D n.BB=2
> ##D n.NN=0
> ##D validation.corr(n.BB,n.NN=0,corr.vec=NULL,corr.mat)
> ##D 
> ##D corr.matc=corr.mat[3:6,3:6]
> ##D validation.corr(n.BB=0,n.NN=4,corr.vec=NULL,corr.mat=corr.matc)
> ##D 
> ##D corr.mat[2,1]=0.5
> ##D validation.corr(n.BB,n.NN,corr.vec=NULL,corr.mat)
> ##D 
> ##D corr.mat[1,2]=0.5
> ##D corr.mat[3,1]=1.5
> ##D corr.mat[1,3]=1.5
> ##D validation.corr(n.BB,n.NN,corr.vec=NULL,corr.mat)
> ##D 
> ##D npd<-matrix(c(1,     0.477, 0.644, 0.478, 0.651, 0.826,
> ##D                0.477, 1,     0.516, 0.233, 0.682, 0.75,
> ##D                0.644, 0.516, 1,     0.599, 0.581, 0.742,
> ##D                0.478, 0.233, 0.599, 1,     0.741, 0.8,
> ##D                0.651, 0.682, 0.581, 0.741, 1,     0.798,
> ##D                0.826, 0.75,  0.742, 0.8,   0.798, 1),
> ##D                nrow = 6, ncol = 6)
> ##D 
> ##D validation.corr(n.BB,n.NN,corr.vec=NULL,corr.mat=npd)
> ##D 
> ##D n.BB=1
> ##D n.NN=0
> ##D corr.mat<-diag(1)
> ##D validation.corr(n.BB,n.NN,corr.vec=NULL,corr.mat)
> ##D 
> ## End(Not run)
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>