0

我正在为一个研究项目创建一些网络变量。该代码来自 igraph-package 并且运行平稳,但是检查中心度和密度的结果有些结果高于 1,这是不可能的。代码中可能有问题吗?还是包有错误?

这是代码:

WINDOW <- 3
YEARS = c(1975:2016)
Acquirer_inventor_edges <- read_dta("~/Research projects/M&A - R&D 
structure/Data/test file.dta")


finaldata <- data.frame(
firmid = numeric(),
year   = numeric(),
dens   = numeric(),
centr_c = numeric(),

stringsAsFactors = FALSE
)

for (j in unique(Acquirer_inventor_edges$a_COMP_gvkey)) {
print(j)
y <- subset.data.frame(Acquirer_inventor_edges, a_COMP_gvkey == j) 

for (f in YEARS) {
x <- subset.data.frame(y, appyear>=f-WINDOW & appyear<f) 
firm <- graph_from_data_frame(x, directed=TRUE, vertices=NULL) #make the 
firm, 3year window subset a network
density <- edge_density(firm, loops=TRUE)

centrality_cent = centralize(degree(firm),normalize=FALSE)/((vcount(firm)-1)*(vcount(firm)-2))


firm_level_data <- data.frame(
  firmid = j,
  year   = f,
  dens   = density,
  centr_c = centrality_cent,

  stringsAsFactors = FALSE
)

finaldata <- rbind(finaldata, firm_level_data)
} 
} 
4

0 回答 0