Are there any R Packages for Graphs (shortest path, etc.)? - r

I know that R is statistical pkg, but probably there is library to work with graphs and find shortest path btw 2 nodes.
PS actually, I've found igraph and e1071, which one is better?
Thank you

Sure, there's a Task View that gathers a fair number of the graph-related Packages. (The page linked to is a CRAN portal, which uses iframes, so i can't directly link to the Graph Task View. So from the page linked to here, click on Task Views near the top of the LHS column, then click on the Task View gR, near the bottom of the list.
Among the Packages there, igraph, for instance, has graph-theoretic functions such as you have mentioned in your Q.
igraph versus e1071--well, igraph is coded in C; it's very fast. I have not compared it with e1071 though.
What i do know is that these two packages differ a great deal in scope: e1071 is a collection of functions (at least originally) for a University course (i believe the unusual name 'e1071' refers to the course identifier), while. e1071 indeed contains a graph theoretic functions, but the majority of the Package's functions are directed to machine learning.
iGraph on the other hand is a dedicated graph theoretic Package. iGraph has many more dedicated functions, as well as constructors for a number of common graph types.

Related

Difference between using "gr()" via Plots and installing GR.jl package

I have installed the Plots.jl package and using "gr()" command.
Then, I have come across GR.jl on https://gr-framework.org/julia.html
I am confused what is the difference between the two.
Could someone please cast insight into this?
Thanks,
GR.jl is a plotting package in Julia, actually a Julia wrapper to the whole GR framework, a really fast and powerful plotting framework with front- and backend capabilities. It is entirely useful and usable on it's own.
Plots.jl is meta-plotting package in Julia, which aims to provide a convenient terse syntax for creating plots with a number of different plotting packages. Plots thus does not do any plotting itself - it takes your input commands and translates them to calls to other plotting packages, called "backends". This is currently implemented for 5 different packages: PyPlot, GR, Plotly, PGFPlots and InspectDR. GR is by far the most widely used backend though (and currently the default).
A goal of Plots is to allow package owners to define "recipes", which are descriptions of how to plot a custom type (such as a Shapefile, a Phylogeny, a Cluster object etc), but without depending on Plots. This makes it possible to plot types with recipes defined with Plots, but without interfering with any other plotting packages.
So, though GR is usable on it's own, many users find that the higher-level syntax for Plots is nicer in everyday use, and enjoy the extra usefulness of recipes.

igraph vs sna: can one do something well the other can't or does poorly?

When it comes to network analysis in R, I am a relatively familiar with igraph but not at all with sna.
My question are:
Are these two libraries compatible? i.e. Can I apply an operation from sna to a graph created in igraph and vice versa?
Are there tasks that are performed more efficiently in one package
than in the another?
Which library has a more comprehensible range of operations?
Overall, are there any strong reasons to do network analysis in R using either igraph or sna ?
ps. Does any of the these packages allow for multilayer (multiplex) network analysis?
My sort of big picture take on the differences between the two packages is that igraph is more geared toward graph theory and mathematical models of networks and sna is more geared toward statistical models of (primarily social) networks. The creators of igraph (I think) mostly have a background in computer sciences, while the sna people are sociologists and statisticians. I primarily work in sna (and related packages that comprise the statnet suite of packages -- I am in the social sciences), but use igraph often as well, sometimes within the same script.
To answer your specific questions:
1) No, they are not. Many of the functions in igraph have the same name in sna and this causes conflicts. An igraph graph cannot be used in an sna function. The package intergraph was created to make it easy to switch between sna and igraph. So I could send an igraph graph to an sna function by passing to to intergraph first -- e.g. sna::evcent(intergraph::asNetwork(g)), assuming g is an igraph network. If you use both together in a script, you need to specifically call out the package when running a function or load and unload as needed.
2) In my experience, I have not found one to be more efficient than the other. Both are well developed and maintained packages. I believe that igraph is a bit better suited for large graphs--it has some functions that are modified to save on computational time when run on large graphs. But I do not have direct experience here. Although I would say that igraph is generally better at visualizations.
3) I would say that neither has an edge in comprehensiveness. Both do all the main network analysis stuff (centrality, network topology). They differ in their more "advanced" features. See my general point--they are geared to overlapping but distinct issues in network analysis. There's a lot of stuff in sna that is not available in igraph (e.g. related to statistical inference, like QAP regression [netlm / netlogit] or network autocorrelation models [lnam]), and vice versa (community detection functions like cluster_fast_greedy, for example). sna is extended by a number of compatible packages that do things like latent space models and exponential random graph models.
4) Ceterius paribus, no. To me, the choice is primarily needs driven. If you are interested in statistical inference, you need to work in sna. If not, igraph generally serves. Based on the questions at stack overflow, igraph seems to be more popular, but that of course could be due to selection bias. For that reason alone, if I didn't need to statistically model networks, I would probably mostly use igraph. Again, both packages are great, serving overlapping, but slightly different needs.
Not sure what you mean by "multilayer network analysis" but both igraph and sna work with multiplex networks. You can certainly analyze multiplex network and multilevel networks in sna. (Here, multiplex meaning a networks with a variety of tie types (e.g. friendship and advice) and multilevel meaning either nested networks or multiple networks from the same population (the terminology is a bit confused at this point).) It depends on what you want to do, and often takes some wrangling, but it is possible to an extent.

R programming spectrum analysis

hello am new to R programming in r studio . I will be analyzing the spectral data of raman spectrum in future.
which package will be useful to for the spectral data analysis.I would like to learn that package. I have attached the image how I want to analyze. Please give me suggestions, how to plot the graph as shown in the fig in r studio
thanks in advance
There is a free package called hyperSpec that was specifically designed to handle spectral data together with associated extra data (e.g. experimental parameters etc.). The package also provides interface for common operations, like baseline correction, selection of spectral ranges, normalization, PCA, etc. Moreover, there is a host of plotting functions.
You can install it from CRAN with install.packages("hyperSpec"), however, as of today the CRAN version is outdated. I would recommend you to fetch the recent build from gitHub and install it via Rstudio (look for packages->install->from package archive file).
hyperSpec comes with an extensive documentation and example datasets. To browse through tutorials, run
browseVignettes("hyperSpec")
Plotting is as easy as
plot(chondro) # left plot
qplotspc(chondro) + ggtitle("Example dataset") # right plot
To import your own data, look for functions inside of hyperSpec, whose name starts with read. Just start typing hyperSpec::read and a pop-up will appear. A lot of device-specific data formats are supported. See vignette("fileio") for details.

How can I generate GN benchmark graphs for community detection in igraph?

I'm using R and igraph package to detect communities in graphs, but I haven't found a precise way of creating graphs with community features like the ones used in several papers about community detection.
I wish I could generate graphs using Girvan-Newman benchmark, so I could specify the k_out and k_in variables (the degree of links outside and inside the communities, respectively) and create such graphs.
Use a stochastic blockmodel, http://igraph.org/r/doc/sample_sbm.html.
The above link (http://igraph.org/r/doc/sbm.game.html) doesn't work correctly.
However, there is a LFR benchmark, which generalize the GN benchmark, available for this purpose. We can find it on https://sites.google.com/site/santofortunato/inthepress2.
The graph outputs of the benchmark can be imported directly into R by functions such as read.table or read.csv. The community information is also available as output of the benchmark. Hence, the community comparision function can be used.

Implementation of Particle Swarm Optimization Algorithm in R

I'm checking a simple moving average crossing strategy in R. Instead of running a huge simulation over the 2 dimenional parameter space (length of short term moving average, length of long term moving average), I'd like to implement the Particle Swarm Optimization algorithm to find the optimal parameter values. I've been browsing through the web and was reading that this algorithm was very effective. Moreover, the way the algorithm works fascinates me...
Does anybody of you guys have experience with implementing this algorithm in R? Are there useful packages that can be used?
Thanks a lot for your comments.
Martin
Well, there is a package available on CRAN called pso, and indeed it is a particle swarm optimizer (PSO).
I recommend this package.
It is under actively development (last update 22 Sep 2010) and is consistent with the reference implementation for PSO. In addition, the package includes functions for diagnostics and plotting results.
It certainly appears to be a sophisticated package yet the main function interface (the function psoptim) is straightforward--just pass in a few parameters that describe your problem domain, and a cost function.
More precisely, the key arguments to pass in when you call psoptim:
dimensions of the problem, as a vector
(par);
lower and upper bounds for each
variable (lower, upper); and
a cost function (fn)
There are other parameters in the psoptim method signature; those are generally related to convergence criteria and the like).
Are there any other PSO implementations in R?
There is an R Package called ppso for (parallel PSO). It is available on R-Forge. I do not know anything about this package; i have downloaded it and skimmed the documentation, but that's it.
Beyond those two, none that i am aware of. About three months ago, I looked for R implementations of the more popular meta-heuristics. This is the only pso implementation i am aware of. The R bindings to the Gnu Scientific Library GSL) has a simulated annealing algorithm, but none of the biologically inspired meta-heuristics.
The other place to look is of course the CRAN Task View for Optimization. I did not find another PSO implementation other than what i've recited here, though there are quite a few packages listed there and most of them i did not check other than looking at the name and one-sentence summary.

Resources