is.GNARnet {GNAR} | R Documentation |
Functions to check and create GNARnet objects
Description
is.GNARnet
returns either TRUE or FALSE according to a series of GNARnet checks. as.GNARnet
returns a GNARnet object from an input weights matrix, 'igraph' object, or a GNARnet without assigned class.
Usage
is.GNARnet(x)
as.GNARnet(x)
Arguments
x |
the network to be tested or object to be converted |
Details
The is.GNARnet
function checks whether the network passes a series of tests:
Is it a list containing $edges and $dist
Are the $edges and $dist lists of the same length
Are each of the elements of $edges the same length as the corresponding $dist element
Do the edges only contain valid entries, 1,...,nnodes (or
NULL
)Is it labelled as
GNARnet
classAre no duplicate edges present
Are all distances positive
Are there no self-loops in the network
The as.GNARnet
function converts igraph objects to GNARnet form, other possible inputs are adjacency matrices, and lists with $edges
and $dist
entries of the correct form.
Value
is.GNARnet
returns TRUE
or FALSE
corresponding to passing the above tests.
as.GNARnet
returns a GNARnet
object.
Examples
#check that the example network meets the criteria above
is.GNARnet(fiveNet)
#convert to igraph and back again
as.GNARnet(GNARtoigraph(fiveNet))
#generate a new network with three nodes
#edges 1->2, 2->1, 2->3
#dist 1, 2, 1
#note 1->2 and 2->1 are of different lengths
threeEdge <- list(c(2), c(1,3), NULL)
threeDist <- list(c(1), c(2,1), NULL)
threeNet <- list(edges=threeEdge, dist=threeDist)
#check if this is a GNARnet
is.GNARnet(threeNet)
#use as.GNARnet to change the class
threeNet <- as.GNARnet(threeNet)
#check if this is a GNARnet now
is.GNARnet(threeNet)