Description Usage Arguments Details Value Author(s) See Also Examples

Generates adjacency matrix from an edgelist and vice versa.

1 2 3 4 5 6 7 8 9 | ```
edgelist_to_adjmat(edgelist, w = NULL, t0 = NULL, t1 = NULL,
t = NULL, simplify = TRUE,
undirected = getOption("diffnet.undirected"),
self = getOption("diffnet.self"),
multiple = getOption("diffnet.multiple"), keep.isolates = TRUE,
recode.ids = TRUE)
adjmat_to_edgelist(graph, undirected = getOption("diffnet.undirected",
FALSE), keep.isolates = getOption("diffnet.keep.isolates", TRUE))
``` |

`edgelist` |
Two column matrix/data.frame in the form of ego -source- and alter -target- (see details). |

`w` |
Numeric vector. Strength of ties (optional). |

`t0` |
Integer vector. Starting time of the ties (optional). |

`t1` |
Integer vector. Finishing time of the ties (optional). |

`t` |
Integer scalar. Repeat the network |

`simplify` |
Logical scalar. When TRUE and |

`undirected` |
Logical scalar. When |

`self` |
Logical scalar. When |

`multiple` |
Logical scalar. When |

`keep.isolates` |
Logical scalar. When FALSE, rows with |

`recode.ids` |
Logical scalar. When TRUE ids are recoded using |

`graph` |
Any class of accepted graph format (see |

When converting from edglist to adjmat the function will `recode`

the
edgelist before starting. The user can keep track after the recording by checking
the resulting adjacency matrices' `row.names`

. In the case that the
user decides skipping the recoding (because wants to keep vertices index numbers,
implying that the resulting graph will have isolated vertices), he can override
this by setting `recode.ids=FALSE`

(see example).

When multiple edges are included, `multiple=TRUE`

,each vertex between *{i,j}* will be counted
as many times it appears in the edgelist. So if a vertex *{i,j}* appears 2
times, the adjacency matrix element `(i,j)`

will be 2.

Edges with incomplete information (missing data on `w`

or `times`

) are
not included on the graph. Incomplete cases are tagged using `complete.cases`

and can be retrieved by the user by accessing the attribute `incomplete`

.

Were the case that either ego or alter are missing (i.e. `NA`

values), the
function will either way include the non-missing vertex. See below for an example
of this.

The function performs several checks before starting to create the adjacency matrix. These are:

Dimensions of the inputs, such as number of columns and length of vectors

Having complete cases. If anly edge has a non-numeric value such as NAs or NULL in either

`times`

or`w`

, it will be removed. A full list of such edges can be retrieved from the attribute`incomplete`

Nodes and times ids coding

`recode.ids=FALSE`

is useful when the vertices ids have already been
coded. For example, after having use `adjmat_to_edgelist`

, ids are
correctly encoded, so when going back (using `edgelist_to_adjmat`

)
`recode.ids`

should be FALSE.

In the case of `edgelist_to_adjmat`

either an adjacency matrix
(if times is NULL) or an array of these (if times is not null). For
`adjmat_to_edgelist`

the output is an edgelist with the following columns:

`ego` |
Origin of the tie. |

`alter` |
Target of the tie. |

`value` |
Value in the adjacency matrix. |

`time` |
Either a 1 (if the network is static) or the time stamp of the tie. |

George G. Vega Yon & Thomas W. Valente

Other data management functions: `diffnet-class`

,
`egonet_attrs`

, `isolated`

,
`survey_to_diffnet`

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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | ```
# Base data
set.seed(123)
n <- 5
edgelist <- rgraph_er(n, as.edgelist=TRUE, p=.2)[,c("ego","alter")]
times <- sample.int(3, nrow(edgelist), replace=TRUE)
w <- abs(rnorm(nrow(edgelist)))
# Simple example
edgelist_to_adjmat(edgelist)
edgelist_to_adjmat(edgelist, undirected = TRUE)
# Using w
edgelist_to_adjmat(edgelist, w)
edgelist_to_adjmat(edgelist, w, undirected = TRUE)
# Using times
edgelist_to_adjmat(edgelist, t0 = times)
edgelist_to_adjmat(edgelist, t0 = times, undirected = TRUE)
# Using times and w
edgelist_to_adjmat(edgelist, t0 = times, w = w)
edgelist_to_adjmat(edgelist, t0 = times, undirected = TRUE, w = w)
# Not recoding ----------------------------------------------------
# Notice that vertices 3, 4 and 5 are not present in this graph.
graph <- matrix(c(
1,2,6,
6,6,7
), ncol=2)
# Generates an adjmat of size 4 x 4
edgelist_to_adjmat(graph)
# Generates an adjmat of size 7 x 7
edgelist_to_adjmat(graph, recode.ids=FALSE)
# Dynamic with spells -------------------------------------------------------
edgelist <- rbind(
c(1,2,NA,1990),
c(2,3,NA,1991),
c(3,4,1991,1992),
c(4,1,1992,1993),
c(1,2,1993,1993)
)
graph <- edgelist_to_adjmat(edgelist[,1:2], t0=edgelist[,3], t1=edgelist[,4])
# Creating a diffnet object with it so we can apply the plot_diffnet function
diffnet <- as_diffnet(graph, toa=1:4)
plot_diffnet(diffnet, label=rownames(diffnet))
# Missing alter in the edgelist ---------------------------------------------
data(fakeEdgelist)
# Notice that edge 202 is isolated
fakeEdgelist
# The function still includes vertex 202
edgelist_to_adjmat(fakeEdgelist[,1:2])
edgelist
``` |

srdyal/diffusiontest documentation built on July 31, 2018, 2:14 a.m.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.