Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set.seed(42)
- g <- sample_bipartite(100, 10, type = c("gnp"), p=.03, directed = FALSE)
- gproj <- bipartite_projection(ga, types=NULL, multiplicity = TRUE)
- g1 <- gproj[[1]]
- V(g1)$name <- 1:vcount(g1) #this gets their actual vertex id to show as label
- V(g1)$name
- components <- decompose.graph(g1)
- largest <- which.max(sapply(components, vcount))
- largest #this tells me the first component is largest
- lc <- components[[1]]
- lc
- plot(lc)
- cg1 <- constraint(lc)
- cg1 #constraint for all connected vertices is calculated
- #Create g2, some vertices in g1, some are new
- rel <- data.frame( rel1 =
- c(3), rel2 =
- c(2000), stringsAsFactors = F) #create edgelist of g2, one vertex in lc, one vertex new
- g2 <- graph.data.frame(rel, directed=FALSE)
- #combine graphs and calculate constraint on combined graph
- #g1 is used instead of lc because relationships in g2 may connect previously isolated vertices/components
- g3 <- g1 + g2
- components1 <- decompose.graph(g3)
- largest1 <- which.max(sapply(components1, vcount))
- largest1 #this tells me the first component is largest
- lc1 <- components1[[1]]
- plot(lc1)
- cg3 <- constraint(lc1)
- cg3 #now constraint vertices close to 2000 is 'NA'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement