我正在为研究项目创建一些网络变量。该代码来自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)
}
}