R igraph package - centrality degree & density return results > 1

359 Views Asked by At

I'm creating some network variables for a research project. The code is from the igraph-package and runs smoothly, but checking the results for centrality degree and density some of the outcomes are higher than 1, what is impossible. Might there be something wrong in the code? Or is there an error in the package?

This is the code:

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)
} 
} 
0

There are 0 best solutions below