简体   繁体   English

计算R中的度,紧密度和中间度

[英]Calculate degree, closeness and betweenness in R

I have a data table which consists of names of users who post in the same thread in a forum, it looks like that: X1 X2 1. g79 kian 2. g79 greyracer 3. g79 oldskoo1 ... 我有一个数据表,该数据表由在论坛中相同主题中发布的用户名称组成,它看起来像是:X1 X2 1. g79 kian 2. g79 greyracer 3. g79 oldskoo1 ...

I need to calculate degree, closeness and betweenness. 我需要计算度,亲密度和中间度。 I'm using the following code: 我正在使用以下代码:

library(igraph)
setwd("/Volumes/NATASHKA/api/R files")
load("edgelist_one_mode.rda")
load("map.rda")
load ("result.rda")
el <- as.matrix(whatwewant)
el[,1] <- as.character(el[,1])
el[,2] <- as.character(el[,2])
g <- graph.data.frame(el, directed=FALSE)
plot(g, edge.arrow.size=.5)
indegreeG <- degree(g, mode="in")
outdegreeG <- degree(g, mode="out")
totaldegreeG <- degree(g)
inclosenessG <- closeness(g, mode='in')
outclosenessG <- closeness(g, mode='out')
totalclosenessG <- closeness(g)
betweennessG <- betweenness(g)
forumG <- data.frame(V(g)$name, indegreeG, outdegreeG, totaldegreeG, inclosenessG,    outclosenessG, totalclosenessG, betweennessG)
write.table(forumG,file="forumG.csv",sep=";")

The question is why do I get the same values for in-degree, out-degree and total-degree, the same for closeness? 问题是,为什么我获得的度数,度数和总度数的值相同,而接近度的值相同? Besides, at the beginning I have 41213 users, but after analysis (when I calculate degree, etc..) I only have 37874. How could I lose so many observations? 此外,一开始我有41213个用户,但是经过分析(当我计算学位等时),我只有37874个用户。我怎么会失去这么多观察结果? Please tell me if I have a mistake in the code. 如果我的代码有误,请告诉我。

Thanks 谢谢

The reason you get the same value for in-degree, out-degree and total degree is because you are creating an undirected network with the graph.data.frame(el, directed=FALSE) . 之所以获得度数,度数和总度数相同的原因是因为您正在使用graph.data.frame(el, directed=FALSE)创建一个无向网络。 In an undirected network, the number of links from a node and to a node are the same and they are both equal to the global degree. 在无向网络中,从节点到节点的链接数相同,并且都等于全局范围。

If you want a directed network, you will need to do graph.data.frame(el, directed=TRUE) . 如果需要定向网络,则需要执行graph.data.frame(el, directed=TRUE) It will create a directed network in which the id in the first column of your dataframe is the id of the node sending the tie and the id in the second column indicates the node receiving that tie. 它将创建一个定向网络,其中数据框第一列中的ID是发送平局的节点的ID,第二列中的ID指示接收该平局的节点。

As for loosing nodes, my guess would be that you have some individuals who never interact with anyone and therefore are lost when you transform your two-mode network into one-mode (I assume you do this but don't show us how you do it because of your line: load("edgelist_one_mode.rda") ) 至于松散的节点,我的猜测是您有一些人从未与任何人互动,因此当您将双模网络转换为单模时会迷路(我假设您这样做但未向我们展示您如何做因为你的行: load("edgelist_one_mode.rda")

Short of a reproducible example, I think that is all I can deduce from your code. 缺少可重现的示例,我认为这就是我可以从您的代码中得出的全部内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM