Blog CeON-u » Michał http://blog.ceon.pl Blog Centrum Otwartej Nauki Fri, 30 Aug 2013 20:09:45 +0000 pl-PL hourly 1 http://wordpress.org/?v=3.5.1 Package intergraph goes 2.0 http://bc.bojanorama.pl/2013/05/package-intergraph-goes-2-0/ http://bc.bojanorama.pl/2013/05/package-intergraph-goes-2-0/#comments Thu, 09 May 2013 23:39:49 +0000 Michał http://bc.bojanorama.pl/?p=608 Yesterday I submitted a new version (marked 2.0-0) of package ‘intergraph’ to CRAN. There are some major changes and bug fixes. Here is a summary:

  • The package supports “igraph” objects created with ‘igraph’ version 0.6-0 and newer (vertex indexing starting from 1, not 0) only!
  • Main functions for converting network data between object classes “igraph” and “network” are now called asIgraph and asNetwork.
  • There is a generic function asDF that converts network object to a list of two data frames containing (1) edge list with edge attributes and (2) vertex database with vertex attributes
  • Functions asNetwork and asIgraph allow for creating network objects from data frames (edgelists with edge attributes and vertex databases with vertex attributes).

I have written a short tutorial on using the package. It is available on package home page on R-Forge. Here is the direct link.

Usage experiences and bug reports are more than welcome.

]]>
http://bc.bojanorama.pl/2013/05/package-intergraph-goes-2-0/feed/ 0
Assorted links http://bc.bojanorama.pl/2013/04/assorted-links/ http://bc.bojanorama.pl/2013/04/assorted-links/#comments Thu, 04 Apr 2013 14:34:44 +0000 Michał http://brokeringclosure.wordpress.com/?p=465 Some assorted links collected this week:

There are discussions in various places about merits, pitfalls, and misunderstandings related to buzzwords “bigdata”, “data science” (what a useless term it is…) etc., analysis being “data-driven” or “evidence-based” etc. Perhaps I will make a separate post on that at some point… For now:

]]>
http://bc.bojanorama.pl/2013/04/assorted-links/feed/ 0
Correction to intergraph update http://bc.bojanorama.pl/2012/06/correction-to-intergraph-update/ http://bc.bojanorama.pl/2012/06/correction-to-intergraph-update/#comments Tue, 19 Jun 2012 21:52:39 +0000 Michał http://brokeringclosure.wordpress.com/?p=471 It turned out that I wrote the last post on “intergraph” package too hastily. After some feedback from CRAN maintainers and deliberation I decided to release the updated version of the “intergraph” package under the  original name (so no new package “intergraph0″) with version number 1.2. This version relies on legacy “igraph” version 0.5, which is now called “igraph0″. Package “intergraph” 1.2 is now available on CRAN.

Meanwhile, I’m working on new version of “intergraph”, scheduled to be ver. 1.3, which will rely on new version 0.6 of “igraph”.

I am sorry for the mess.

]]>
http://bc.bojanorama.pl/2012/06/correction-to-intergraph-update/feed/ 0
Updates to package ‘intergraph’ http://bc.bojanorama.pl/2012/06/updates-to-package-intergraph/ http://bc.bojanorama.pl/2012/06/updates-to-package-intergraph/#comments Mon, 18 Jun 2012 11:05:30 +0000 Michał http://brokeringclosure.wordpress.com/?p=467 On June 17 a new version (0.6) of package ”igraphwas released. This new version abandoned the old way of indexing graph vertices with consecutive numbers starting from 0. The new version now numbers the vertices starting from 1, which is more consistent with the general R convention of indexing vectors, matrices, etc. Because this change is not backward-compatible, there is now a separate package called “igraph0″ which still uses the old 0-convention.

These changes affect the package “intergraph“.

A new version of “intergraph” (ver 1.3) is being developed to be compatible with the new “igraph” 0.6. Until it is ready, there is now package “intergraph” version 1.2 available on CRAN, which still uses the old 0-convention. It relies on legacy version of “igraph” (version 0.5, now called “igraph0″ on CRAN).

To sum up:

  • If you have code that still uses the old version of “igraph” (earlier than 0.6) you should load package “igraph0″ instead of “igraph”, and use package “intergraph” version 1.2.
  • If you already started using the new version of “igraph” (0.6 or later), unfortunately you have to wait until a new version of “intergraph” (1.3) is released.

Edit

As I wrote in the next post, in the end there is no package “intergraph0″, just the new version 1.2. Consequently, I have edited the description above.

]]>
http://bc.bojanorama.pl/2012/06/updates-to-package-intergraph/feed/ 0
New and old news http://bc.bojanorama.pl/2012/05/new-and-old-news/ http://bc.bojanorama.pl/2012/05/new-and-old-news/#comments Wed, 23 May 2012 23:20:52 +0000 Michał http://brokeringclosure.wordpress.com/?p=458

PhD cover

It’s been a while since I wrote something, not without a reason. Last months were terribly busy for me. First of all, I defended my PhD (yay!). Second, a lot of my time was consumed by writing proposals. Third, upcoming changes to R package ‘igraph‘ caused an unscheduled but necessary review of some of my R packages. Nevertheless, I should be able get back to more regular blogging from now on.

For now three links from May:

  1. Wired now features a new blog (first post on January 7, 2012) devoted to social sciences called Social Dimension written by Samuel Arbesman. Recent interesting posts include:
  2. David Smith (Revolution Analytics) writes about recent EU High Court ruling in a case of SAS vs WPS. SAS is a data analytic software developed by SAS Institute and WPS is a low-cost clone of SAS capable of processing SAS data files and selected types of SAS scripts. The High Court ruled that “the programming languages cannot be copyrighted”. Here is the official press release.
  3. The Promising Future for Mathematical Sociology at ASA Math Sociology blog Permutations.
]]>
http://bc.bojanorama.pl/2012/05/new-and-old-news/feed/ 0
SNA with R workshop at Sunbelt XXXII in Redondo Beach http://bc.bojanorama.pl/2012/03/sna-with-r-workshop-at-sunbelt-xxxii-in-redondo-beach/ http://bc.bojanorama.pl/2012/03/sna-with-r-workshop-at-sunbelt-xxxii-in-redondo-beach/#comments Tue, 13 Mar 2012 23:17:39 +0000 Michał http://brokeringclosure.wordpress.com/?p=448 I am currently in Redondo Beach, CA at the Sunbelt XXXII social networks conference. The program is thick from numerous interesting talks so the event promises to be very interesting.

Today in the morning I gave the workshop “Introduction to Social Network Analysis with R”. Over 50 people registered. I am grateful to all the participants for attendance. I hope the workshop was useful to you, despite some of the technical difficulties in the beginning!

Here are some pictures:

]]>
http://bc.bojanorama.pl/2012/03/sna-with-r-workshop-at-sunbelt-xxxii-in-redondo-beach/feed/ 0
Package ‘intergraph’ (1.1-0) released! http://bc.bojanorama.pl/2011/09/package-intergraph-1-1-0-released/ http://bc.bojanorama.pl/2011/09/package-intergraph-1-1-0-released/#comments Tue, 20 Sep 2011 16:44:44 +0000 Michał http://brokeringclosure.wordpress.com/?p=444 I just released the first official version of the ‘intergraph’ R package.

With the functions provided in the current version (1.1-0) you can convert network data objects between classes ‘igraph’ and ‘network’. The package supports directed and undirected networks, and handles the node, tie, and network (graph) attributes. Mutliplex networks (i.e., with possibly multiple ties per dyad) are also supported, although not thoroughly tested.

Network objects of class ‘network’ (from package “network”) can be used to store hypergraphs. Conversion of these is not supported at this time.

Both ‘igraph’ and ‘network’ classes can be used to explicitly deal with bipartite networks. Currently, for the bipartite networks, only the conversion from ‘igraph’ to ‘network’ will work. I hope to be able to add the conversion in the other direction in future releases.

You can download and install the package from CRAN. The package sources are hosted on R-Forge here.

]]>
http://bc.bojanorama.pl/2011/09/package-intergraph-1-1-0-released/feed/ 0
Shortest paths to/from nodes of a certain type http://bc.bojanorama.pl/2011/09/shortest-paths-tofrom-nodes-of-a-certain-type/ http://bc.bojanorama.pl/2011/09/shortest-paths-tofrom-nodes-of-a-certain-type/#comments Wed, 14 Sep 2011 17:55:43 +0000 Michał http://brokeringclosure.wordpress.com/?p=431 Elijah asked the following via SOCNET mailing list:

I was wondering if anyone knew of a script or tool which would give me the network distance of nodes to a particular class of nodes.  I think of this as an Erdos number, except instead of getting the distance to one node, I want the distance to the closest node of a particular class.  Let’s say I have a network of people and I know their professions.  Some are Students, some are Journalists and a small number are Engineers.  I’d like to be able to find out the network distance of each node to the closest Engineer node. It would be particularly useful if the script also had the option to total edge weight into the calculation.

If you get your network data into R it is fairly straightforward to do this using igraph package. Here is the function:

# shortest paths to nodes with a specified value on certain node attribute
spnt <- function(g, aname, avalue, weights=NULL, ...)
{
  require(igraph)
  stopifnot(inherits(g, "igraph"))
  a <- get.vertex.attribute(g, aname)
  m <- shortest.paths(g, v=V(g)[a==avalue], weights=weights, ...)
  apply(m, 2, min)
}

It assumes that ‘g’ is a network (object of class ‘igraph’), ‘aname’ is a name of the node attribute, ‘avalue’ is the value of the attribute ‘aname’ that designates the nodes to/from which we would like to calculate distances, finally ‘weights’ can be optionally used to include weights in the calculation (as a numeric vector).

The function will return a vector of distances in ‘g’ from all the nodes to the closest node that have a value ‘avalue’ on attribute ‘aname’.

As an example consider the network below. It is undirected and has 15 nodes. It has two attributes defined: a node attribute called “color” having values “orange”, “lightblue”, and “lightgreen”, and an edge attribute called “w” with values 1 or 2. Both attributes are shown in the picture as a node color and edge label. The numbers on the nodes are node ids.

Assuming that the network is called ‘g’ we can use the function above in the following way:

# from lightblue nodes to all others
spnt(g, "color", "lightblue")
## [1] 0 1 2 1 2 3 0 1 2 1 2 3 2 3 4
 
# from orange nodes to all others
spnt(g, "color", "orange")
## [1] 1 0 1 0 1 0 1 0 0 2 1 0 2 1 0
 
# to lightblue, but using weights (shortest path = minimal weight)
spnt(g, "color", "lightblue", weights=E(g)$w)
## [1] 0 2 3 1 2 3 0 2 4 2 3 4 3 5 5

A couple of end notes:

  • In the result vector you will get 0s for the nodes of specified type, i.e. in the last example there are 0s for the “lightblue” nodes.
  • If a certain node is not connected (directly or via other nodes) to any node of specified type the vector will contain ‘Inf’ (plus infinity).
  • The algorithm will not accept negative weights. But this limitation can be effectively dodged by transforming the weights so that they are all positive (for example adding some number), performing the computation, and then transforming back the results to the original scale.
  • You can exploit other features of ‘shortest.paths’ function, on which this function is based. Any extra arguments to ‘spnt’ are passed to ‘shortest.paths’. For example, if the network is directed you can calculate shortest paths that are either incoming, or outgoing (via ‘mode’ argument). See help page of ‘shortest.paths’.
]]>
http://bc.bojanorama.pl/2011/09/shortest-paths-tofrom-nodes-of-a-certain-type/feed/ 0
Social contagion story update http://bc.bojanorama.pl/2011/06/social-contagion-story-update/ http://bc.bojanorama.pl/2011/06/social-contagion-story-update/#comments Wed, 08 Jun 2011 17:04:38 +0000 Michał http://brokeringclosure.wordpress.com/?p=422 July last year I wrote a note about the stream of papers by Nicholas Christakis and James Fowler (or CF) and coauthors on social contagion of many things (obesity, smoking, loneliness to name the few). I also wrote about a paper by Russel Lyons that provided a detailed critique of the analyzes presented in the papers by CF. See my earlier post for details.

Meanwhile, the paper by Lyons, which was available through ArXiv repository since July last year, got published in Statistics, Politics, and Policy journal here (thanks to Ilan Talmud for noticing that). All the substantial points remained largely unchanged as compared to the ArXiv paper. However, the author supplemented the paper with a truly hair-raising account of the struggle he had to go through to publish the paper: rejections from several journals without reviews or even reasonable explanations. I definitely recommend reading it.

Using the occasion, I also recommend two other papers related to this “debate”:

The first one is a response of Christakis & Fowler to some other critical comments on related issues:

Fowler, James H. and Nicholas A. Christakis. 2008b. “Estimating peer effects on health in social networks: A response to Cohen-Cole and Fletcher and Trogdon, Nonnemaker, and Pais.” Journal of Health Economics 27:1400–1405.

The second one is by Hans Noel and Brendan Nyhan

The “Unfriending” Problem The Consequences of Homophily in Friendship Retention for Causal Estimates of Social Influence” (download)

in which they use MCMC simulations to show, in short, how network homophily could have confounded the purported contagion effects reported in the studies by CF.

]]>
http://bc.bojanorama.pl/2011/06/social-contagion-story-update/feed/ 0
Math in the social sciences, with discussion http://bc.bojanorama.pl/2011/03/math-in-the-social-sciences-with-discussion/ http://bc.bojanorama.pl/2011/03/math-in-the-social-sciences-with-discussion/#comments Tue, 08 Mar 2011 18:23:09 +0000 Michał http://brokeringclosure.wordpress.com/?p=380 Nice discussion on the usefulness, or lack thereof, of mathematics and formal theory building in the social sciences. Make sure you have a look at the comments. More or less chronologically:

With some appraisal here, here, and to some extent here.

Somewhat in parallel, a discussion about the death of theoretical (read mathematical) economics at econlog:

All in all, I subscribe to Fabio’s call with both hands.

My subjective list of advantages of formal theory building in social sciences supplementing the one at orgtheory.net:

  1. If a theory is, among other things, a logically coherent set of propositions then formalizing it is just a translation to a language that makes analyzing it, especially deducing consequences, much easier. And this applies to whatever the subject of the theory is.
  2. Most of the empirical studies in sociology are analyzed using some form of statistical reasoning, which is mathematical. Given that, building a formal theory of the studied phenomenon should in principle allow for a tighter connection between the theory and empirics (c.f. The Theory-Gap in Social Network Analysis by Mark Granovetter).
  3. I would also add the “accumulativeness”, much in the line of Formal Rational Choice Theory: A Cumulative Science of Politics by  David Lalman, Joe Oppenheimer, and Piotr Swistak. Although, I have to admit, after having spent 5 years or so studying mathematical sociology and selective works from mathematical economics, the cumulation is sometimes difficult to observe from a local point of view and local time scale of individual researcher. There are so many specific models (strong assumptions etc.), and it is frequently hard to understand the bigger picture. Perhaps it is just the question of time for a “unification” to arrive, … or a researcher…
  4. ?
]]>
http://bc.bojanorama.pl/2011/03/math-in-the-social-sciences-with-discussion/feed/ 0