[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] degree according to vertex attributes

From: S. M. Ali Abbas
Subject: Re: [igraph] degree according to vertex attributes
Date: Mon, 01 Oct 2012 17:02:59 +0100
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120907 Thunderbird/15.0.1

On a similar note, if you are interested to calculate E-I (External-Internal) Index (Krackhardt and Stern (1988)), which identifies group embedding by using this formula:

E - I / ( E + I )

Details: http://www.faculty.ucr.edu/~hanneman/nettext/C8_Embedding.html#EI

I have written a function sometime ago which returns a matrix for each unique value of a particular attribute of vertices in a graph. For instance, in your case, it will a return 2  x (unique cities) matrix, where the first column will be the city's name and the second will be its E-I index. You just need to call this function as:

resultantEIMatrix <- getEIIndex (g, "City")

Here goes the function:

# Returns a matrix of 2 x length(unique_attribute_values)
getEIIndex <- function(graph, colName){
# Get unique_col values for colName attributes for vertices
unique_col <- unique(get.vertex.attribute(graph, colName))
# Create a matrix with 2 columns and length(unique_col) number of rows
# First column will contain the unique value of an attribute, and the second one the calcuate E-I Index
# For each unique column value, identify external and internal edges
for (j in 1:length(unique_col)){
# Get the jth unique attribute value
val <- unique_col[j]
# Get all vertices which have the same attribute values as val
tmp1 <- which(get.vertex.attribute(graph, colName) == val)
# Get all vertices which have different attribute values than val
tmp2 <- which(get.vertex.attribute(graph, colName) != val)
# Count all edges having the same attribute value
i <-length(E(graph)[tmp1 %--% tmp1])
# Count all edges having different attribute value
e <- length(E(graph)[tmp1 %--% tmp2])
# Calculate the E-I Index
ei <- (e-i)/(e+i)
# Put the unique value at column 1
m[j, 1]= val
# Put the calculated E-I index at column 2
m[j, 2]= ei
# Return the matrix

Hope it help!


On 01/10/2012 16:29, Tamás Nepusz wrote:
Hi Dominik,

As you wrote earlier, the first problem can be resolved by using delete.vertices=FALSE when calling subgraph.edges (sorry, I thought this is the default).

Re the second problem: use get.edgelist(graph, names=FALSE); this will give you a numeric edge list and this is what you need in later steps.


igraph-help mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]