Simulates a sparse precision matrix from a binary adjacency matrix
theta
encoding conditional independence in a Gaussian Graphical Model.
SimulatePrecision(
pk = NULL,
theta,
v_within = c(0.5, 1),
v_between = c(0, 0.1),
v_sign = c(-1, 1),
continuous = TRUE,
pd_strategy = "diagonally_dominant",
ev_xx = NULL,
scale = TRUE,
u_list = c(1e-10, 1),
tol = .Machine$double.eps^0.25
)
A list with:
true simulated precision matrix.
value of the constant u used to ensure that omega
is
positive definite.
vector of the number of variables per group in the simulated
dataset. The number of nodes in the simulated graph is sum(pk)
. With
multiple groups, the simulated (partial) correlation matrix has a block
structure, where blocks arise from the integration of the length(pk)
groups. This argument is only used if theta
is not provided.
binary and symmetric adjacency matrix encoding the conditional independence structure.
vector defining the (range of) nonzero entries in the
diagonal blocks of the precision matrix. These values must be between -1
and 1 if pd_strategy="min_eigenvalue"
. If continuous=FALSE
,
v_within
is the set of possible precision values. If
continuous=TRUE
, v_within
is the range of possible precision
values.
vector defining the (range of) nonzero entries in the
off-diagonal blocks of the precision matrix. This argument is the same as
v_within
but for off-diagonal blocks. It is only used if
length(pk)>1
.
vector of possible signs for precision matrix entries. Possible
inputs are: -1
for positive partial correlations, 1
for
negative partial correlations, or c(-1, 1)
for both positive and
negative partial correlations.
logical indicating whether to sample precision values from
a uniform distribution between the minimum and maximum values in
v_within
(diagonal blocks) or v_between
(off-diagonal blocks)
(if continuous=TRUE
) or from proposed values in v_within
(diagonal blocks) or v_between
(off-diagonal blocks) (if
continuous=FALSE
).
method to ensure that the generated precision matrix is
positive definite (and hence can be a covariance matrix). If
pd_strategy="diagonally_dominant"
, the precision matrix is made
diagonally dominant by setting the diagonal entries to the sum of absolute
values on the corresponding row and a constant u. If
pd_strategy="min_eigenvalue"
, diagonal entries are set to the sum of
the absolute value of the smallest eigenvalue of the precision matrix with
zeros on the diagonal and a constant u.
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=TRUE
) or covariance (if
scale_ev=FALSE
) matrix divided by the sum of eigenvalues. If
ev_xx=NULL
(the default), the constant u is chosen by maximising the
contrast of the correlation matrix.
logical indicating if the proportion of explained variance by
PC1 should be computed from the correlation (scale=TRUE
) or
covariance (scale=FALSE
) matrix.
vector with two numeric values defining the range of values to explore for constant u.
accuracy for the search of parameter u as defined in
optimise
.
Entries that are equal to zero in the adjacency matrix theta
are also equal to zero in the generated precision matrix. These zero
entries indicate conditional independence between the corresponding pair of
variables (see SimulateGraphical
).
Argument pk
can be specified to create groups of variables and allow
for nonzero precision entries to be sampled from different distributions
between two variables belonging to the same group or to different groups.
If continuous=FALSE
, nonzero off-diagonal entries of the precision
matrix are sampled from a discrete uniform distribution taking values in
v_within
(for entries in the diagonal block) or v_between
(for entries in off-diagonal blocks). If continuous=TRUE
, nonzero
off-diagonal entries are sampled from a continuous uniform distribution
taking values in the range given by v_within
or v_between
.
Diagonal entries of the precision matrix are defined to ensure positive
definiteness as described in MakePositiveDefinite
.
ourstabilityselectionfake
SimulateGraphical
, MakePositiveDefinite
# Simulation of an adjacency matrix
theta <- SimulateAdjacency(pk = c(5, 5), nu_within = 0.7)
print(theta)
# Simulation of a precision matrix maximising the contrast
simul <- SimulatePrecision(theta = theta)
print(simul$omega)
# Simulation of a precision matrix with specific ev by PC1
simul <- SimulatePrecision(
theta = theta,
pd_strategy = "min_eigenvalue",
ev_xx = 0.3, scale = TRUE
)
print(simul$omega)
Run the code above in your browser using DataLab