VisCov {VisCov} | R Documentation |
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, eta = 1, 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: |
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:
|
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 reference.
Value
A list of variables to pass for selecting panels.
References
Tokuda, T., Goodrich, B., Van Mechelen, I., Gelman, A. and Tuerlinckx, F. (submitted). Visualizing Distributions of Covariance Matrices.
Examples
## Figures in the paper (Tokuda, Goodrich, Van Mechelen, Gelman, and Tuerlinckx)
## Example 1 (Figure 1 in the paper)
set.seed(1234)
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)
## Example 2 (Figure 2 in the paper)
set.seed(1234)
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))
## Example 3 (Figure 3 in the paper)
set.seed(1234)
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))
## Example 4 (Figure 4 in the paper)
set.seed(1234)
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))
## Example 5 (Figure 5 in the paper)
set.seed(1234)
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))
## Example 6 (Figure 6 in the paper)
set.seed(1234)
distribution = "LKJ"
eta = 5
dim = 100
param = list(prob = 0.5, dim = dim, eta=eta, scaleCov = diag(1,dim))
CovPlotData = VisCov(distribution, param,title.logical = FALSE)
panelSelectCorr(CovPlotData)
## Example 7 (Figure 7 in the paper)
set.seed(1234)
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))
## Example 8 (Figure 8 in the paper)
distribution = "Wishart"
set.seed(1234)
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))
## Example 9 (Figure 9 in the paper)
set.seed(1234)
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)