LISTSERV mailing list manager LISTSERV 16.0

Help for SOCNET Archives


SOCNET Archives

SOCNET Archives


SOCNET@LISTS.UFL.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

SOCNET Home

SOCNET Home

SOCNET  July 2015

SOCNET July 2015

Subject:

Re: SNA in R

From:

Michał Bojanowski <[log in to unmask]>

Reply-To:

Michał Bojanowski <[log in to unmask]>

Date:

Mon, 13 Jul 2015 11:16:03 +0200

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (359 lines)

*****  To join INSNA, visit http://www.insna.org  *****

Hi all,

Similar to Katya, I am also a joint igraph+statnet user.
Just to supplement and comment upon the answers already contributed:


>>>>     I have noticed some compatibility issues when I load igraph and
>>>>     statnet into R at the same time.  I'm preferring to use statnet
>>>>     because of ergms.  I'm hoping I can get a little help with the
>>>>     following:

The "incompatibilities" are because both packages provide functions
with the same names. Similar names conflicts as igraph vs network
happen between igraph and the sna package.

I wrote a short note on this
http://bc.bojanorama.pl/2010/08/namespaces-and-name-conflicts/
It was a serious problem 5 years ago (the post is a bit outdated now),
and it is a nuisance rather than a serious problem now.
As Simone wrote (his email contained in Katya's reply) you can use
`::` (double colon) do refer to a function from a particular package
unequivocally. An example:

library(network)
library(igraph)

m <- matrix(rbinom(25,1,.4),5,5)
diag(m) <- 0

# use network
net <- network::network(m, directed=FALSE)
# use igraph
ig <- igraph::graph.adjacency(m, mode="undirected")

plot(net)
plot(ig)




A side note: triple-colon `:::` is for calling functions from package
namespace which were not exported by the package author for public
use, probably for a reason. Using them directly with `:::` is a bad
practice.

Another strategy is to attach and detach network or igraph package
when it is not needed with

library(igraph)

# code  using igraph here

detach(package:igraph, force=TRUE)
library(network)

# code using network/statnet here

detach(package:network, force=TRUE)

# ... and so on...






>>>>     2. Alternatively, is there an easier way to convert data formats
>>>>     between the network structure of the network package and the graph
>>>>     structure of the igraph package?

As Alex mentioned, I wrote `intergraph`
(http://mbojan.github.io/intergraph/) just for that. See short
tutorial here http://mbojan.github.io/intergraph/howto.html



>> When you call a function, say from igraph, simply use
>>
>> igraph::degree(g)
>
> Good point, and that would work for degree(). The problem is it won't help
> in cases where the function is not called directly by the user, but by
> another function within the package.

Since couple of years now both igraph and network have namespaces. As
package namespaces are "sealed" this should not be a problem anymore
because package code should not be affected by clashes in the user
workspace. However, this is of course a theory, i.e. R now provides
tools to dodge these problems, it is another matter whether R users
and developers use them, and use them properly. In practice you might
still get errors when using two packages with conflicting function
names.



> I believe Gabor Csardi had mentioned he was going to fix the naming issues
> in one of the coming igraph releases -- not sure if he's gotten around to
> that yet or not.

That is correct. New function names in igraph have been introduced in
igraph ver. 1.0-0 (released in late June this year). Old names are
still functional though so you will get the same name conflicts as
before. I guess Gabor will make the old function names deprecated in
future releases.



>>> I've recently put together a quick tutorial on network visualization in R
>>> that might be of some use for this - it's available here:
>>> http://kateto.net/network-visualization and as a PDF here:
>>> http://bitly.com/networkviz

This tutorial is great (as I already Tweeted :)). Congrats! Highly recommended.


Best,
Michal




































On Mon, Jul 13, 2015 at 9:58 AM, Katherine Ognyanova <[log in to unmask]> wrote:
> *****  To join INSNA, visit http://www.insna.org  *****
>
> Hey Simo,
>
> Good point, and that would work for degree(). The problem is it won't help
> in cases where the function is not called directly by the user, but by
> another function within the package.
>
> For example, both 'igraph' and 'network' have functions named "add.edges()"
> and "add.vertices()". So say I load 'igraph' first and then 'network',
> masking the igraph add.vertices() function. Now, if I try to use another
> 'igraph' function that contains a call to add.vertices (say one of the ones
> that generate trees, the name escapes me now) -- that would result in lots
> of complaining and error-throwing.
>
> I believe Gabor Csardi had mentioned he was going to fix the naming issues
> in one of the coming igraph releases -- not sure if he's gotten around to
> that yet or not.
>
> Best!
> Katya
>
>
> On 7/13/2015 3:33 AM, Simone Gabbriellini wrote:
>>
>> Katherine,
>>
>> When you call a function, say from igraph, simply use
>>
>> igraph::degree(g)
>>
>> This way, no confusion arises!
>>
>> HTH,
>> Simo
>>
>> Ps: it could be igraph::: instead of igraph:: I don't have my Mac with me
>> and cannot check for sure
>>
>> Sent from my iPhone
>>
>>
>>> On 13 Jul 2015, at 08:34, Katherine Ognyanova <[log in to unmask]> wrote:
>>>
>>> *****  To join INSNA, visit http://www.insna.org  *****
>>>
>>> Hey Ian,
>>>
>>> Same deal here - I use both packages and switch back and forth. By the
>>> way, I find it best not to keep both loaded at same time (or at least not
>>> for long). They do have overlapping function names, and sooner or later that
>>> will cause something to throw an error.
>>>
>>> Alex has covered converting igraph to network objects and back. I usually
>>> just do that by extracting a matrix or edgelist from one and reading that
>>> into the other one (with get.adjacency() or get.edgelist() in igraph, and
>>> with as.matrix.network() in statnet).
>>>
>>> On question (1), pretty much all of the metrics you mention in are
>>> available in the 'sna' package. So for a network named 'net', you can do:
>>>
>>> library(sna)
>>> connectedness(net)                               # Krackhardt
>>> connectedness
>>> hierarchy(net, measure="krackhardt")   # Krackhardt hierarchy
>>> efficiency(net)                                        # Krackhardt
>>> efficiency
>>>
>>> On question (3), you can use the argument 'vertex.cex' to change the size
>>> of the nodes when plotting a network object. So if you want to size by
>>> degree, this should work:
>>>
>>> library(sna)
>>> deg <- degree(net)
>>> plot(net,  vertex.cex=deg)
>>>
>>> I've recently put together a quick tutorial on network visualization in R
>>> that might be of some use for this - it's available here:
>>> http://kateto.net/network-visualization and as a PDF here:
>>> http://bitly.com/networkviz
>>>
>>> Best!
>>> Katya
>>>
>>>> On 7/13/2015 1:22 AM, Alex Stivala wrote:
>>>> ***** To join INSNA, visit http://www.insna.org *****
>>>> Ian,
>>>>
>>>> I use statnet and igraph at the same time, and have found the R
>>>> intergraph package by Michal Bojanowski:
>>>>
>>>> http://cran.r-project.org/web/packages/intergraph/index.html
>>>>
>>>> to be very useful for converting between the igraph and statnet network
>>>> formats.
>>>>
>>>> For example:
>>>>
>>>> library(igraph)
>>>> library(statnet)
>>>> library(intergraph)
>>>>
>>>> netscience <- nexus.get('netscience')
>>>> nNetscience <- asNetwork(netscience)
>>>>
>>>> system.time(nsmodel <- ergm(nNetscience ~ edges + altkstar(2.0,
>>>> fixed=TRUE) +  gwesp(log(2.0), fixed=TRUE) + gwdsp(log(2.0),
>>>> fixed=TRUE), control=control.ergm(main.method="Stepping",
>>>> MCMC.burnin=1e+6,MCMC.interval=1e+04,MCMC.samplesize=1e+05)))
>>>>
>>>> summary(nsmodel)
>>>>
>>>> Note sure I can help with your other particular questions, I prefer to
>>>> use igraph for plotting (where it is relatively easy to do things like
>>>> your question 3) and computing various statistics (question 1), I use
>>>> statnet primarily for ergm.
>>>>
>>>> Regards,
>>>> Alex..
>>>>
>>>>
>>>> On Mon, Jul 13, 2015 at 3:10 PM, Ian McCulloh <[log in to unmask]
>>>> <mailto:[log in to unmask]>> wrote:
>>>>
>>>>     *****  To join INSNA, visit http://www.insna.org  *****
>>>>
>>>>     Hello,
>>>>
>>>>     I have noticed some compatibility issues when I load igraph and
>>>>     statnet into R at the same time.  I'm preferring to use statnet
>>>>     because of ergms.  I'm hoping I can get a little help with the
>>>>     following:
>>>>
>>>>     1. How do you calculate connectedness, hierarchy, krackhardt
>>>>     efficiency, and least upper boundedness using the network package,
>>>>     SNA, or any of the statnet dependencies?
>>>>
>>>>     2. Alternatively, is there an easier way to convert data formats
>>>>     between the network structure of the network package and the graph
>>>>     structure of the igraph package?
>>>>
>>>>     3. How do you size nodes by an attribute measure such as centrality
>>>>     using the network package?
>>>>
>>>>     Thanks,
>>>>
>>>>     Ian McCulloh
>>>>
>>>>
>>>> _____________________________________________________________________
>>>>     SOCNET is a service of INSNA, the professional association for
>>>> social
>>>>     network researchers (http://www.insna.org). To unsubscribe, send
>>>>     an email message to [log in to unmask]
>>>>     <mailto:[log in to unmask]> containing the line
>>>>     UNSUBSCRIBE SOCNET in the body of the message.
>>>>
>>>>
>>>> _____________________________________________________________________
>>>> SOCNET is a service of INSNA, the professional association for social
>>>> network researchers (http://www.insna.org). To unsubscribe, send an
>>>> email message to [log in to unmask] containing the line UNSUBSCRIBE
>>>> SOCNET in the body of the message.
>>>
>>>
>>> --
>>>
>>> _______________________________________
>>>
>>> Katherine Ognyanova, Ph.D.
>>> Postdoctoral Researcher, The Lazer Lab
>>> Web: www.kateto.net, Twitter: @ognyanova
>>> _______________________________________
>>>
>>> _____________________________________________________________________
>>> SOCNET is a service of INSNA, the professional association for social
>>> network researchers (http://www.insna.org). To unsubscribe, send
>>> an email message to [log in to unmask] containing the line
>>> UNSUBSCRIBE SOCNET in the body of the message.
>>
>>
>>
>
> --
>
> _______________________________________
>
> Katherine Ognyanova, Ph.D.
> Postdoctoral Researcher, The Lazer Lab
> Web: www.kateto.net, Twitter: @ognyanova
> _______________________________________
>
> _____________________________________________________________________
> SOCNET is a service of INSNA, the professional association for social
> network researchers (http://www.insna.org). To unsubscribe, send
> an email message to [log in to unmask] containing the line
> UNSUBSCRIBE SOCNET in the body of the message.

_____________________________________________________________________
SOCNET is a service of INSNA, the professional association for social
network researchers (http://www.insna.org). To unsubscribe, send
an email message to [log in to unmask] containing the line
UNSUBSCRIBE SOCNET in the body of the message.

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008, Week 62
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
January 2004
December 2003
November 2003
October 2003
September 2003
August 2003
July 2003
June 2003
May 2003
April 2003
March 2003
February 2003
January 2003
December 2002
November 2002
October 2002
September 2002
August 2002
July 2002
June 2002
May 2002
April 2002
March 2002
February 2002
January 2002
December 2001
November 2001
October 2001
September 2001
August 2001
July 2001
June 2001
May 2001

ATOM RSS1 RSS2



LISTS.UFL.EDU

CataList Email List Search Powered by the LISTSERV Email List Manager