Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. set.seed(42)
  2. g <- sample_bipartite(100, 10, type = c("gnp"), p=.03, directed = FALSE)
  3. gproj <- bipartite_projection(ga, types=NULL, multiplicity = TRUE)
  4. g1 <- gproj[[1]]
  5. V(g1)$name <- 1:vcount(g1) #this gets their actual vertex id to show as label
  6. V(g1)$name
  7. components <- decompose.graph(g1)
  8. largest <- which.max(sapply(components, vcount))
  9. largest #this tells me the first component is largest
  10. lc <- components[[1]]
  11. lc
  12. plot(lc)
  13. cg1 <- constraint(lc)
  14. cg1 #constraint for all connected vertices is calculated
  15.  
  16. #Create g2, some vertices in g1, some are new
  17. rel <- data.frame( rel1 =
  18. c(3), rel2 =
  19. c(2000), stringsAsFactors = F) #create edgelist of g2, one vertex in lc, one vertex new
  20. g2 <- graph.data.frame(rel, directed=FALSE)
  21.  
  22. #combine graphs and calculate constraint on combined graph
  23. #g1 is used instead of lc because relationships in g2 may connect previously isolated vertices/components
  24. g3 <- g1 + g2
  25. components1 <- decompose.graph(g3)
  26. largest1 <- which.max(sapply(components1, vcount))
  27. largest1 #this tells me the first component is largest
  28. lc1 <- components1[[1]]
  29. plot(lc1)
  30. cg3 <- constraint(lc1)
  31. cg3 #now constraint vertices close to 2000 is 'NA'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement