ego_semnet {corpustools} R Documentation

## Create an ego network

### Description

Create an ego network from an igraph object.

### Usage

ego_semnet(
g,
vertex_names,
depth = 1,
only_filter_vertices = T,
weight_attr = "weight",
min_weight = NULL,
top_edges = NULL,
max_edges_level = NULL,
directed = c("out", "in")
)


### Arguments

 g an igraph object vertex_names a character string with the names of the ego vertices/nodes depth the number of degrees from the ego vertices/nodes that are included. 1 means that only the direct neighbours are included only_filter_vertices if True, the algorithm will only filter out vertices/nodes that are not in the ego network. If False (default) then it also filters out the edges. weight_attr the name of the edge attribute. if NA, no weight is used, and min_weight and top_edges are ignored min_weight a number indicating the minimum weight top_edges for each vertex within the given depth, only keep the top n edges with the strongest edge weight. Can also be a vector of the same length as the depth value, in which case a different value is used at each level: first value for level 1, second value for level 2, etc. max_edges_level the maximum number of edges to be added at each level of depth. directed if the network is directed, specify whether 'out' degrees or 'in' degrees are used

### Details

The function is similar to the ego function in igraph, but with some notable differences. Firstly, if multiple vertex_names are given, the ego network for both is given in 1 network (whereas igraph creates a list of networks). Secondly, the min_weight and top_edges parameters can be used to focus on the strongest edges.

### Examples

tc = create_tcorpus(c('a b c', 'd e f', 'a d'))
g = semnet(tc, 'token')

igraph::get.data.frame(g)
plot_semnet(g)
## only keep nodes directly connected to given node
g_ego = ego_semnet(g, 'e')
igraph::get.data.frame(g_ego)
plot_semnet(g_ego)

## only keep edges directly connected to given node
g_ego = ego_semnet(g, 'e', only_filter_vertices = FALSE)
igraph::get.data.frame(g_ego)
plot_semnet(g_ego)

## only keep nodes connected to given node with a specified degree (i.e. distance)
g_ego = ego_semnet(g, 'e', depth = 2)
igraph::get.data.frame(g_ego)
plot_semnet(g_ego)


[Package corpustools version 0.4.10 Index]