Package 'VisCov'

Title: Visualizing of Distributions of Covariance Matrices
Description: Visualizing of distributions of covariance matrices. The package implements the methodology described in Tokuda, T., Goodrich, B., Van Mechelen, I., Gelman, A., & Tuerlinckx, F. (2012) <https://stat.columbia.edu/~gelman/research/unpublished/Visualization.pdf>.
Authors: Tomoki Tokuda [aut], Ben Goodrich [ctb], Iven Van Mechelen [ctb], Andrew Gelman [ctb], Francis Tuerlinckx [ctb], Kristof Meers [cre]
Maintainer: Kristof Meers <[email protected]>
License: GPL (>= 3)
Version: 1.4.0
Built: 2024-10-25 05:25:53 UTC
Source: CRAN

Help Index


Selecting a panel(s) by mouse

Description

To select (using the mouse) one or more panels from a four-layered plot for a single distribution. The selected panels will be drawn in separate graphics window.

Usage

panelSelect(panel.no, CovPlotData)

Arguments

panel.no

an integer indicating the number of panels that one wishes to select

CovPlotData

the output list returned by VisCov

Details

After drawing a graph by VisCov, one can select and draw the specified number of panels by clicking the mouse on the panels of interest.

Value

No return value, called for side effects

References

Tokuda, T., Goodrich, B., Van Mechelen, I., Gelman, A., & Tuerlinckx, F. (submitted). Visualizing Distributions of Covariance Matrices

Examples

CovPlotData = VisCov()
panelSelect(panel.no = 1, CovPlotData) ## Click once on the plot you want to select
panelSelect(panel.no = 4, CovPlotData) ## Click four times on the plots you want to select

Selecting panels from several distributions

Description

To draw the selected panels from several distributions generated by VisCov.

Usage

panelSelectMultiple(selected.condition, CovPlotDataMultiple, 
                    range.logical.contour = FALSE, range.logical.all = TRUE, row = FALSE)

Arguments

selected.condition

a vector of strings containing types of the panels that one wishes to select: For layer 1, "vari", "cor"; for layer 2, "scatter1", "scatter2", "scatter3", "scatter4", "scatter5"; for layer 3, "contour", "threeD"; for layer 4, "Effective.Variance", "Effective.Dependence", "Effective.Dependence.submatrix"

CovPlotDataMultiple

a list of objects returned by VisCov

range.logical.all

a logical value indicating whether the ranges in the panels are set as the same over different sets of samples. For the histograms, the ranges of frequencies are set as the same over the different sets of samples

range.logical.contour

a logical value indicating whether the ranges of the contour plots are set as the same over different sets of samples when range.logical.all is TRUE

row

a logical value whether the panels belonging to the same set of samples are arranged in the same row. If it is FALSE, they are arranged in the same column

Value

No return value, called for side effects

References

Tokuda, T., Goodrich, B., Van Mechelen, I., Gelman, A., & Tuerlinckx, F. (submitted). Visualizing Distributions of Covariance Matrices

Examples

distribution = "Inverse Wishart"
dim = 4
param = list(prob = 0.5, dim = dim, nu = dim+1, scaleCov = diag(1,dim))
CovPlotData1 = VisCov(distribution, param, title.logical = FALSE)
distribution = "Inverse Wishart"
dim = 4
param = list(prob = 0.5, dim = dim, nu = dim+50, scaleCov = diag(1,dim))
CovPlotData2 = VisCov(distribution, param, title.logical = FALSE)
selected.condition = c("scatter1", "scatter4", "contour", "Effective.Dependence")
panelSelectMultiple(selected.condition, list(CovPlotData1, CovPlotData2))

Visualizing of distributions of covariance matrices

Description

To generate samples from a specific distribution of covariance matrices, draw the four-layered graphs and return the sampled matrices and the related information on the distribution.

Usage

VisCov(distribution = "Inverse Wishart", param = list(prob = 0.5, dim = 4, nu = 5, 
       scaleCov = diag(1,4)), title = distribution, Nsamples = 1000, Ncontours = 100, 
       logSD = TRUE, histogram.Variance = TRUE, histogram.Correlation = TRUE, 
       histogram.Effective.Variance = TRUE, histogram.Effective.Dependence = TRUE, 
       extreme.regio = "Effective Dependence", title.logical = TRUE)

Arguments

distribution

a distribution to be plotted among:

"Inverse Wishart", "Scaled Inverse Wishart", "Scaled Inverse Wishart for correlation", "Scaled with uniform on correlation", "Wishart", and "User defined distribution"

title.logical

a logical value indicating whether a title should be given to the graph

title

title of the graph

Nsamples

the number of samples for all plots except the contour plot

Ncontours

the number of samples for the contour plot

logSD

a logical value indicating whether the natural logarithm of the standard deviation is plotted

histogram.Variance

a logical value indicating whether the univariate graph of the (log) standard deviation is a histogram (TRUE) or a density (FALSE)

histogram.Correlation

a logical value indicating whether the univariate graph of the correlation is a histogram (TRUE) or a density curve (FALSE)

histogram.Effective.Variance

a logical value indicating whether the univariate graph of the effective variance is a histogram (TRUE) or a density curve (FALSE)

histogram.Effective.Dependence

a logical value indicating whether the univariate graph of the effective dependence is a histogram (TRUE) or a density curve (FALSE)

extreme.regio

indicates whether the coloring of extreme samples (in red and blue) is based on the "Effective Dependence" or "Effective Variance". If neither of them is specified, there is no coloring.

param

a list of parameters consisting of the following objects: mat, a list of covariance matrices; applicable only when distribution = "User defined distribution"; prob, mass concentration in the equiprobability contour plot; dim, dimension of matrices; nu, degrees of freedom for the inverse Wishart or Wishart distributions; scaleCov, scale matrix for the inverse Wishart or Wishart distributions; mu0 and s0 are the mean and the standard deviation for the folded normal distribution, applicable when distribution is "Scaled Inverse Wishart", "Scaled Inverse Wishart for correlation" or "Scaled with uniform on correlation"

Details

VisCov generates samples from a specific distribution of covariance matrices (or user defined distribution), draws the four-layered graphs and returns the sampled matrices and the related information on the distribution. For more detail, see Tokuda et al. in the following references.

Value

List of variables to pass for selecting panels

References

Tokuda, T., Goodrich, B., Van Mechelen, I., Gelman, A., & Tuerlinckx, F. (submitted). Visualizing Distributions of Covariance Matrices

Examples

###### Figures in the paper (Tokuda, Goodrich, Van Mechelen, Gelman, and Tuerlinckx)
## Figure 1
distribution = "Inverse Wishart"
dim = 4
param = list(prob = 0.5, dim = dim, nu = dim+1, scaleCov = diag(1,dim))
CovPlotData = VisCov(distribution, param, title.logical = FALSE)

## Figure 2
distribution = "Inverse Wishart"
dim = 4
param = list(prob = 0.5, dim = dim, nu = dim+1, scaleCov = diag(1,dim))
CovPlotData1 = VisCov(distribution, param, title.logical = FALSE)
distribution = "Inverse Wishart"
dim = 4
param = list(prob = 0.5, dim = dim, nu = dim+50, scaleCov = diag(1,dim))
CovPlotData2 = VisCov(distribution, param, title.logical = FALSE)
selected.condition = c("scatter1", "scatter4", "contour", "Effective.Dependence")
panelSelectMultiple(selected.condition, list(CovPlotData1, CovPlotData2))

## Figure 3

distribution = "Inverse Wishart"
dim = 4
param = list(prob = 0.5, dim = dim, nu = dim+1, scaleCov = diag(1,dim))
CovPlotData1 = VisCov(distribution, param, title.logical = FALSE)
dim = 100
param = list(prob = 0.5, dim = dim, nu = dim+1, scaleCov = diag(1,dim))
CovPlotData2 = VisCov(distribution, param, title.logical = FALSE)
selected.condition = c("Effective.Dependence")
panelSelectMultiple(selected.condition, list(CovPlotData1, CovPlotData2))

## Figure 4
distribution = "Scaled Inverse Wishart for correlation"
dim = 4
param = list(mu0 = 0, s0 = 1, prob = 0.5, dim = dim, nu = dim+1, scaleCov = diag(1,dim))
CovPlotData1 = VisCov(distribution, param, title.logical = FALSE)
param = list(mu0 = 0, s0 = 1,prob = 0.5, dim = dim, nu = dim+50, scaleCov = diag(1,dim))
CovPlotData2 = VisCov(distribution, param, title.logical = FALSE)
selected.condition = c("scatter1", "scatter2", "scatter4", "contour")
panelSelectMultiple(selected.condition, list(CovPlotData1, CovPlotData2))

## Figure 5

distribution = "Scaled with uniform on correlation"
dim = 4
param = list(mu0 = 0, s0 = 1, prob = 0.5, dim = dim)
CovPlotData1 = VisCov(distribution, param, title.logical = FALSE)
dim = 50
param = list(mu0 = 0, s0 = 1, prob = 0.5, dim = dim)
CovPlotData2 = VisCov(distribution, param,title.logical = FALSE)
selected.condition = c("scatter2", "scatter4", "contour","Effective.Dependence.submatrix")
panelSelectMultiple(selected.condition, list(CovPlotData1, CovPlotData2))

## Figure 6
distribution = "Scaled Inverse Wishart"
dim = 4
param = list(mu0 = 0, s0 = 1, prob = 0.5, dim = dim, nu = dim+1, scaleCov = diag(1,dim))
CovPlotData1 = VisCov(distribution, param, title.logical = FALSE)
param = list(mu0 = 0, s0 = 1,prob = 0.5, dim = dim, nu = dim+50, scaleCov = diag(1,dim))
CovPlotData2 = VisCov(distribution, param, title.logical = FALSE)
selected.condition = c("scatter2", "scatter4", "contour","Effective.Dependence")
panelSelectMultiple(selected.condition, list(CovPlotData1,CovPlotData2))

## Figure 7

distribution = "Wishart"
dim = 4
param = list(prob = 0.5, dim = dim, nu = dim+1, scaleCov = diag(1,dim))
CovPlotData1 = VisCov(distribution, param, title.logical = FALSE)
dim = 50
param = list(prob = 0.5, dim = dim, nu = dim+1, scaleCov = diag(1,dim))
CovPlotData2 = VisCov(distribution, param,title.logical = FALSE)
selected.condition = c("scatter2", "scatter4", "contour","Effective.Dependence")
panelSelectMultiple(selected.condition, list(CovPlotData1,CovPlotData2))

## Figure 8

distribution = "User defined distribution"
param = list()
mat = list()
# Generation of covariance matrices
for (i in 1:1000){
index = 0
dim = 50
while (index == 0){
W = matrix(rnorm(dim*dim,0,1),nrow = dim)
svdW= svd(W)
Rho = svdW$u%*%t(svdW$v)
D = diag(rbeta(dim,0.5,5))
Sigma = diag(rnorm(dim,0,1))
Sigma = abs(Sigma)
S = Sigma%*%Rho%*%D%*%t(Rho)%*%Sigma
# Checking positive definiteness
eigenv = eigen(S)$values
if (all(eigenv > 0)) index = 1
if (index ==0){print("zero")}
}
mat[[i]] = S
}
param = list(prob = 0.5, mat = mat)
CovPlotData = VisCov(distribution, param , title.logical = FALSE)