Description Usage Arguments Details Value Author(s) Examples
View source: R/rags2ridgesFused.R
Simulate data from a pdimensional (zeromean) gaussian graphical model (GGM) with a specified (or random) topology and return the sample covariance matrix or matrices. Can also return the original simulated data.
1 2 3 4 5 
n 
A 
p 
A 
topology 
character. The topology to use for the simulations. See the details. 
dataset 
A 
precision 
A 
nonzero 
A 
m 
A 
banded.n 
A 
invwishart 

nu 

Plist 
An optional 
The data is simulated from a zeromean p
dimensional multivariate gaussian distribution with some precision matrix determined by the argument topology
which defines the GGM.
If precision
is TRUE
the population precision matrix is returned.
This is useful to see what the actual wouldbeused precision matrices are.
The available values of topology
are described below.
Unless otherwise stated the diagonal entries are always one.
If m
is 2 or greater block diagonal precision matrices are constructed and used.
"identity"
: uses the identity matrix (diag(p)
) as precision matrix.
Corresponds to no conditional dependencies.
"star"
: simulate from a star topology. Within each block the first
node is selected as the "hub". The offdiagonal entries (1,j) and (j,1)
values taper off with the value 1/(j + 1).
"clique"
: simulate from clique topology where each block is a complete
graph with offdiagonal elements equal to nonzero
.
"complete"
: alias for (and identical to) "clique"
.
"chain"
: simulate from a chain topology where the precision matrix
is a tridiagonal matrix with offdiagonal elements (in each block) given
by argument nonzero
.
"banded"
: precision elements (i,j)
are given by
1/(ij+1) if ij is less than or equal to banded.n
and zero otherwise.
"scalefree"
: The nonzero pattern of each block is generated by a
Barabassi random graph. Nonzero offdiagonal values are given by nonzero
.
Gives are very "hubby" network.
"Barabassi"
: alias for "scalefree"
.
"smallworld"
: The nonzero pattern of each block is generated by a
1dimensional WattsStrogatz random graph with banded.n
starting neighbors and 5\% probability of rewiring.
Nonzero offdiagonal values are given by
nonzero
. Gives are very "bandy" network.
"WattsStrogatz"
: alias for "smallworld"
"randomgraph"
: The nonzero pattern of each block is generated by a
ErdosRenyi random graph where each edge is present with probability 1/p.
Nonzero offdiagonal values are given by nonzero
.
"ErdosRenyi"
: alias for "randomgraph"
When n
has length greater than 1, the datasets are generated i.i.d. given the topology and number of blocks.
Arguments invwishart
and nu
allows for introducing class homogeneity.
Large values of nu
imply high class homogeneity.
nu
must be greater than p + 1
.
More precisely, if invwishart == TRUE
then the constructed precision matrix is used as the scale parameter in an inverse Wishart distribution with nu
degrees of freedom.
Each class covariance is distributed according to this inverse Wishart and independent.
The returned type is dependent on n
and covariance
.
The function generally returns a list
of numeric
matrices with the same length as n
.
If covariance
is FALSE
the simulated datasets with size n[i]
by p
are given in the i
entry of the output.
If covariance
is TRUE
the p
by p
sample covariances of the datasets are given.
When n
has length 1 the list
structure is dropped and the matrix is returned.
Anders E. Bilgrau, Carel F.W. Peeters <[email protected]>, Wessel N. van Wieringen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46  ## Generate some simple sample covariance matrices
createS(n = 10, p = 3)
createS(n = c(3, 4, 5), p = 3)
createS(n = c(32, 55), p = 7)
## Generate some datasets and not sample covariance matrices
createS(c(3, 4), p = 6, dataset = TRUE)
## Generate sample covariance matrices from other topologies:
A < createS(2000, p = 4, topology = "star")
round(solve(A), 3)
B < createS(2000, p = 4, topology = "banded", banded.n = 2)
round(solve(B), 3)
C < createS(2000, p = 4, topology = "clique") # The complete graph (as m = 1)
round(solve(C), 3)
D < createS(2000, p = 4, topology = "chain")
round(solve(D), 3)
## Generate smaple covariance matrices from block topologies:
C3 < createS(2000, p = 10, topology = "clique", m = 3)
round(solve(C3), 1)
C5 < createS(2000, p = 10, topology = "clique", m = 5)
round(solve(C5), 1)
## Can also return the precision matrix to see what happens
## m = 2 blocks, each "banded" with 4 offdiagonal bands
round(createS(1, 12, "banded", m = 2, banded.n = 4, precision = TRUE), 2)
## Simulation using graphgames
round(createS(1, 10, "smallworld", precision = TRUE), 2)
round(createS(1, 5, "scalefree", precision = TRUE), 2)
round(createS(1, 5, "randomgraph", precision = TRUE), 2)
## Simulation using inverse Wishart distributed class covariance
## Low class homogeneity
createS(n = c(10,10), p = 5, "banded", invwishart = TRUE, nu = 10)
## Extremely high class homogeneity
createS(n = c(10,10), p = 5, "banded", invwishart = TRUE, nu = 1e10)
# The precision argument can again be used to see the actual realised class
# precision matrices used when invwishart = TRUE.
# The Plist argument is used to reuse old precision matrices or
# usergenerated ones
P < createS(n = 1, p = 5, "banded", precision = TRUE)
lapply(createS(n = c(1e5, 1e5), p = 5, Plist = list(P, P+1)), solve)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.