This file is indexed.

/usr/lib/R/site-library/igraph/demo/hrg.R is in r-cran-igraph 0.7.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
pause <- function() {
  cat("Press ENTER/RETURN/NEWLINE to continue.")
  readLines(n=1)
  invisible()
}

### Download the Zachary Karate Club network from Nexus

karate <- nexus.get("karate")
karate

pause()

### Optimalize modularity

optcom <- optimal.community(karate)
V(karate)$comm <- membership(optcom)
plot(optcom, karate)

pause()

### Fit a HRG model to the network

hrg <- hrg.fit(karate)
hrg

pause()

### The fitted model, more details

print(hrg, level=5)

pause()

### Plot the full hierarchy, as an igraph graph

ihrg <- as.igraph(hrg)
ihrg$layout <- layout.reingold.tilford
plot(ihrg, vertex.size=10, edge.arrow.size=0.2)

pause()

### Customize the plot a bit, show probabilities and communities

vn <- sub("Actor ", "", V(ihrg)$name)
colbar <- rainbow(length(optcom))
vc <- ifelse(is.na(V(ihrg)$prob), colbar[V(karate)$comm], "darkblue")
V(ihrg)$label <- ifelse(is.na(V(ihrg)$prob), vn, round(V(ihrg)$prob, 2))
par(mar=c(0,0,3,0))
plot(ihrg, vertex.size=10, edge.arrow.size=0.2,
     vertex.shape="none", vertex.label.color=vc,
     main="Hierarchical network model of the Karate Club")

pause()

### Plot it as a dendrogram, looks better if the 'ape' package is installed

dendPlot(hrg)

pause()

### Make a very hierarchical graph

g1 <- graph.full(5)
g2 <- graph.ring(5)

g <- g1 + g2
g <- g + edge(1, vcount(g1)+1)

plot(g)

pause()

### Fit HRG

ghrg <- hrg.fit(g)
dendPlot(ghrg)

pause()

### Create a consensus dendrogram from multiple samples, takes longer...

hcons <- hrg.consensus(g)
hcons$consensus

pause()

### Predict missing edges

pred <- hrg.predict(g)
pred

pause()

### Add some the top 5 predicted edges to the graph, colored red

E(g)$color <- "grey"
lay <- layout.auto(g)
g2 <- add.edges(g, t(pred$edges[1:5,]), color="red")
plot(g2, layout=lay)

pause()

### Add four more predicted edges, colored orange

g3 <- add.edges(g2, t(pred$edges[6:9,]), color="orange")
plot(g3, layout=lay)