总结R中几个网络的中心性统计



我有25年的引文数据(例如,作者1在2010年引用了作者2 5次)。

'data.frame':   7695 obs. of  4 variables:
$ author_1               : chr  "AT" "AT" "AT" "AT" ...
$ author_2               : chr  "BE" "BE" "BE" "BE" ...
$ year                   : int  1995 1997 2000 2003 2006 2007 ...
$ collaborations         : int  1 1 2 4 1 2 3 2 7 2 ...

我必须为5年的每个滑动窗口创建一个加权图(这将给我22个图),并计算所有节点的中心性统计数据。

所需结果:具有5列("window","node","degree","betweenness","closeness")的数据帧。

如果我循环为每个窗口创建一个图(见下面的例子),我最终会得到22个图,从而得到22个对象(矩阵或数据帧),总结每个图的中心性。

#a loop creating 22 networks and saving them to the environment with name "window.x"
years<-c(1995:2020)
for (i in 1:22) {
nam <- paste("window", i, sep = ".")
assign(nam, citations %>%
filter(year >= years[i] &
year <= years[i+4])  %>%
select(author1, author2, collaborations) %>%
group_by(author1, author2, ) %>%
summarize(weight = sum(collaborations),.groups = 'drop'))
}

我正在寻找一种更有效的方法来做到这一点。

我没有你的完整数据,但下面可能是你使用滑动窗口的提示:

> embed(1995:2020,5)[,5:1]
[,1] [,2] [,3] [,4] [,5]
[1,] 1995 1996 1997 1998 1999
[2,] 1996 1997 1998 1999 2000
[3,] 1997 1998 1999 2000 2001
[4,] 1998 1999 2000 2001 2002
[5,] 1999 2000 2001 2002 2003
[6,] 2000 2001 2002 2003 2004
[7,] 2001 2002 2003 2004 2005
[8,] 2002 2003 2004 2005 2006
[9,] 2003 2004 2005 2006 2007
[10,] 2004 2005 2006 2007 2008
[11,] 2005 2006 2007 2008 2009
[12,] 2006 2007 2008 2009 2010
[13,] 2007 2008 2009 2010 2011
[14,] 2008 2009 2010 2011 2012
[15,] 2009 2010 2011 2012 2013
[16,] 2010 2011 2012 2013 2014
[17,] 2011 2012 2013 2014 2015
[18,] 2012 2013 2014 2015 2016
[19,] 2013 2014 2015 2016 2017
[20,] 2014 2015 2016 2017 2018
[21,] 2015 2016 2017 2018 2019
[22,] 2016 2017 2018 2019 2020

然后,您可以按行使用apply来对igraph进行操作。

最新更新