View source: R/createAssoPerm.R
createAssoPerm | R Documentation |
The function creates and returns a matrix with permuted group labels and saves association matrices computed for the permuted data to an external file.
createAssoPerm(
x,
computeAsso = TRUE,
nPerm = 1000L,
cores = 1L,
seed = NULL,
permGroupMat = NULL,
fileStoreAssoPerm = "assoPerm",
append = TRUE,
storeCountsPerm = FALSE,
fileStoreCountsPerm = c("countsPerm1", "countsPerm2"),
logFile = NULL,
verbose = TRUE
)
x |
object of class |
computeAsso |
logical indicating whether the association matrices should
be computed. If |
nPerm |
integer indicating the number of permutations. |
cores |
integer indicating the number of CPU cores used for
permutation tests. If cores > 1, the tests are performed in parallel.
Is limited to the number of available CPU cores determined by
|
seed |
integer giving a seed for reproducibility of the results. |
permGroupMat |
an optional matrix with permuted group labels (with nPerm rows and n1+n2 columns). |
fileStoreAssoPerm |
character giving the name of a file to which the matrix with associations/dissimilarities of the permuted data is saved. Can also be a path. |
append |
logical indicating whether existing files (given by
fileStoreAssoPerm and fileStoreCountsPerm) should be extended.
If |
storeCountsPerm |
logical indicating whether the permuted count matrices
should be saved to an external file. Defaults to |
fileStoreCountsPerm |
character vector with two elements giving the names of two files storing the permuted count matrices belonging to the two groups. |
logFile |
character string naming the log file to which the current
iteration number is written. Defaults
to |
verbose |
logical. If |
Invisible object: Matrix with permuted group labels.
# Load data sets from American Gut Project (from SpiecEasi package)
data("amgut1.filt")
# Generate a random group vector
set.seed(123456)
group <- sample(1:2, nrow(amgut1.filt), replace = TRUE)
# Network construction:
amgut_net <- netConstruct(amgut1.filt, group = group,
measure = "pearson",
filtTax = "highestVar",
filtTaxPar = list(highestVar = 30),
zeroMethod = "pseudoZO", normMethod = "clr")
# Network analysis:
amgut_props <- netAnalyze(amgut_net, clustMethod = "cluster_fast_greedy")
# Use 'createAssoPerm' to create "permuted" count and association matrices,
# which can be reused by netCompare() and diffNet()
# Note:
# createAssoPerm() accepts objects 'amgut_net' and 'amgut_props' as input
createAssoPerm(amgut_props, nPerm = 100L,
computeAsso = TRUE,
fileStoreAssoPerm = "assoPerm",
storeCountsPerm = TRUE,
fileStoreCountsPerm = c("countsPerm1", "countsPerm2"),
append = FALSE, seed = 123456)
# Run netcompare using the stored permutation count matrices
# (association matrices are still computed within netCompare):
amgut_comp1 <- netCompare(amgut_props, permTest = TRUE, nPerm = 100L,
fileLoadCountsPerm = c("countsPerm1",
"countsPerm2"),
seed = 123456)
# Run netcompare using the stored permutation association matrices:
amgut_comp2 <- netCompare(amgut_props, permTest = TRUE, nPerm = 100L,
fileLoadAssoPerm = "assoPerm")
summary(amgut_comp1)
summary(amgut_comp2)
all.equal(amgut_comp1$properties, amgut_comp2$properties)
# Run diffnet using the stored permutation count matrices in diffnet()
diff1 <- diffnet(amgut_net, diffMethod = "permute", nPerm = 100L,
fileLoadCountsPerm = c("countsPerm1", "countsPerm2"))
# Run diffnet using the stored permutation association matrices
diff2 <- diffnet(amgut_net, diffMethod = "permute", nPerm = 100L,
fileLoadAssoPerm = "assoPerm")
#plot(diff1)
#plot(diff2)
# Note: Networks are empty (no significantly different associations)
# for only 100 permutations
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.