igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] two-mode to one-mode with event types/attributes


From: Gábor Csárdi
Subject: Re: [igraph] two-mode to one-mode with event types/attributes
Date: Tue, 15 May 2012 11:45:59 -0400

Hi,

On Mon, May 14, 2012 at 3:22 PM, Andrew Papachristos
<address@hidden> wrote:
> Greetings,
>
> I have one (I hope) easy question, and one may not be as easy.
>
> I have a large two-mode dataset (100,000s of cases) with multiple event
> types.  The data look something like so:
>
> Person  Event Event.Type Event.Time
> Andy 1 a T1
> Bob 2 a T2
> Cindy 3 b T3
> .....
>
> I'm trying to accomplish two things:
>
> 1. Figure out the easiest way to do a two-mode to one-mode conversion.
> Essentially, I'm looking to create a person-by-person network.

This is very easy. First read in the table into a data frame and
create an igraph graph with graph.data.frame():

T <- read.table("<filename>", header=TRUE)
G <- graph.data.frame(T)

Then you need to add a 'type' vertex attribute. If you can tell the
vertex type from the vertex name, then this is easy. E.g. if the
numeric vertex ids are the events, then you can simply do:

V(G)$type <- grepl("^[0-9]+$", V(G)$name)

Finally you can create the two one-mode projections via

bipartite.projection(G)

> 2. See if there is a way, when converting, to keep an event attribute (such
> as event type or time).

This is only supported in igraph 0.6. You can download a nightly build
from http://code.google.com/p/igraph/downloads/list

You need to assign these attributes as vertex attributes. By default
they are used as edge attributes, because they belong to the edges in
your table. Create a second table where the first column contains the
vertex ids and the other columns are the vertex attributes. Then use
this table as the 'vertices' argument to graph.data.frame(). In your
example you can simply drop the first column of 'T' to get this table.
In a real data set, you'll need to remove duplicate rows as well.

One tricky part is that you'll need to include every vertex in the
'vertices' data frame, not very logical, but right now it works this
way. So you'll need to add the people as well:

VT <- T[,-1]
VT <- rbind(VT, data.frame(Event=T[,1], Event.Type=NA, Event.Time=NA))

G2 <- graph.data.frame(T, vertices=VT)
V(G2)$type <- grepl("^[0-9]+$", V(G2)$name)
bipartite.projection(G2)

Best,
Gabor

> Any direction is most welcome.
>
> Best,
> andrew
>
>
>
>
>
> Andrew V. Papachristos
> Robert Wood Johnson Health & Society Scholar ~ Harvard University
> Assistant Professor (on leave) ~ UMass, Amherst - Dept. of Sociology
> address@hidden
> www.papachristos.org
> (413) 545 - 0443
>
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/igraph-help
>



-- 
Gabor Csardi <address@hidden>     MTA KFKI RMKI



reply via email to

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