Print

Print


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