SimulateCorrelation {fake} | R Documentation |
Simulation of a correlation matrix
Description
Simulates a correlation matrix. This is done in three steps with (i) the simulation of an undirected graph encoding conditional independence, (ii) the simulation of a (positive definite) precision matrix given the graph, and (iii) the re-scaling of the inverse of the precision matrix.
Usage
SimulateCorrelation(
pk = 10,
theta = NULL,
implementation = HugeAdjacency,
topology = "random",
nu_within = 0.1,
nu_between = NULL,
nu_mat = NULL,
v_within = c(0.5, 1),
v_between = c(0.1, 0.2),
v_sign = c(-1, 1),
continuous = TRUE,
pd_strategy = "diagonally_dominant",
ev_xx = NULL,
scale_ev = TRUE,
u_list = c(1e-10, 1),
tol = .Machine$double.eps^0.25,
output_matrices = FALSE,
...
)
Arguments
pk |
vector of the number of variables per group in the simulated
dataset. The number of nodes in the simulated graph is |
theta |
optional binary and symmetric adjacency matrix encoding the conditional independence structure. |
implementation |
function for simulation of the graph. By default,
algorithms implemented in |
topology |
topology of the simulated graph. If using
|
nu_within |
probability of having an edge between two nodes belonging to
the same group, as defined in |
nu_between |
probability of having an edge between two nodes belonging
to different groups, as defined in |
nu_mat |
matrix of probabilities of having an edge between nodes
belonging to a given pair of node groups defined in |
v_within |
vector defining the (range of) nonzero entries in the
diagonal blocks of the precision matrix. These values must be between -1
and 1 if |
v_between |
vector defining the (range of) nonzero entries in the
off-diagonal blocks of the precision matrix. This argument is the same as
|
v_sign |
vector of possible signs for precision matrix entries. Possible
inputs are: |
continuous |
logical indicating whether to sample precision values from
a uniform distribution between the minimum and maximum values in
|
pd_strategy |
method to ensure that the generated precision matrix is
positive definite (and hence can be a covariance matrix). If
|
ev_xx |
expected proportion of explained variance by the first Principal
Component (PC1) of a Principal Component Analysis. This is the largest
eigenvalue of the correlation (if |
scale_ev |
logical indicating if the proportion of explained variance by
PC1 should be computed from the correlation ( |
u_list |
vector with two numeric values defining the range of values to explore for constant u. |
tol |
accuracy for the search of parameter u as defined in
|
output_matrices |
logical indicating if the true precision and (partial) correlation matrices should be included in the output. |
... |
additional arguments passed to the graph simulation function
provided in |
Details
In Step 1, the conditional independence structure between the
variables is simulated. This is done using SimulateAdjacency
.
In Step 2, the precision matrix is simulated using
SimulatePrecision
so that (i) its nonzero entries correspond
to edges in the graph simulated in Step 1, and (ii) it is positive definite
(see MakePositiveDefinite
).
In Step 3, the covariance is calculated as the inverse of the precision
matrix. The correlation matrix is then obtained by re-scaling the
covariance matrix (see cov2cor
).
Value
A list with:
sigma |
simulated correlation matrix. |
omega |
simulated precision matrix. Only returned if
|
theta |
adjacency matrix of the
simulated graph. Only returned if |
See Also
SimulatePrecision
, MakePositiveDefinite
Other simulation functions:
SimulateAdjacency()
,
SimulateClustering()
,
SimulateComponents()
,
SimulateGraphical()
,
SimulateRegression()
,
SimulateStructural()
Examples
oldpar <- par(no.readonly = TRUE)
par(mar = rep(7, 4))
# Random correlation matrix
set.seed(1)
simul <- SimulateCorrelation(pk = 10)
Heatmap(simul$sigma,
col = c("navy", "white", "darkred"),
text = TRUE, format = "f", digits = 2,
legend_range = c(-1, 1)
)
# Correlation matrix with homogeneous block structure
set.seed(1)
simul <- SimulateCorrelation(
pk = c(5, 5),
nu_within = 1,
nu_between = 0,
v_sign = -1,
v_within = 1
)
Heatmap(simul$sigma,
col = c("navy", "white", "darkred"),
text = TRUE, format = "f", digits = 2,
legend_range = c(-1, 1)
)
# Correlation matrix with heterogeneous block structure
set.seed(1)
simul <- SimulateCorrelation(
pk = c(5, 5),
nu_within = 0.5,
nu_between = 0,
v_sign = -1
)
Heatmap(simul$sigma,
col = c("navy", "white", "darkred"),
text = TRUE, format = "f", digits = 2,
legend_range = c(-1, 1)
)
par(oldpar)