Skip to content

Assorted links

2013 April 4
tags:
by Michał

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:

Course meeting cancelled (Analysing Social Science Data Using R)

2013 March 11
by Michał

Unfortunately today course meeting is cancelled. The course will resume next week normally. I’m sorry for the inconvenience.

Errata to tutorial script 3 (Analysing Social Science Data Using R)

2013 March 2
by Michał

This is the first update post regarding the course “Analysing Social Science Data Using R” in GSSR. There is a dedicated tag “r4sns” and an RSS feed (also visible on the course webage).

If you recall the meeting from February 25, there was one issue in the tutorial script that did not work. It involved taking a subset from pgss data frame using the square brackets instead of function subset. It turned out there was a typo in the variable name that I didn’t notice: homepop instead of hompop. The correct form should be:
[code lang=”r”]singles <- pgss[ pgss$hompop == 1 , vnames ][/code] I have uploaded the corrected tutorial script to the course website.

Correction to intergraph update

2012 June 19
by Michał

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.

Updates to package ‘intergraph’

2012 June 18
by Michał

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.

New and old news

2012 May 24
tags:
by Michał

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.

SNA with R workshop at Sunbelt XXXII in Redondo Beach

2012 March 14
by Michał

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:

Package ‘intergraph’ (1.1-0) released!

2011 September 20
by Michał

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.

Shortest paths to/from nodes of a certain type

2011 September 14
by Michał

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’.

Social contagion story update

2011 June 8

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 three 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.

The thrid one, which I like the most actually is by Shalizi and Thomas Homophily and Contagion Are Generically Confounded in Observational Social Network Studies (thanks Rense) to be found here.