desmarais-lab / NetworkInference

R implementation to the netinf algorithm. Infers the most likely diffusion network from a set of events
Other
23 stars 1 forks source link
diffusion diffusion-network netinf-algorithm network-analysis r

NetworkInference: Inferring Latent Diffusion Networks

About

This package provides an R implementation of the netinf algorithm created by Gomez-Rodriguez, Leskovec, and Krause (see here for more information and the original C++ implementation). Given a set of events that spread between a set of nodes the algorithm infers the most likely stable diffusion network that is underlying the diffusion process.

Installation

The package can be installed from CRAN:

install.packages("NetworkInference")

The latest development version can be installed from github:

#install.packages(devtools)
devtools::install_github('desmarais-lab/NetworkInference')

Quick start guide

To get started, get your data into the cascades format required by the netinf function:

library(NetworkInference)

# Simulate random cascade data
df <- simulate_rnd_cascades(50, n_node = 20)

# Cast data into `cascades` object
## From long format
cascades <- as_cascade_long(df)

## From wide format
df_matrix <- as.matrix(cascades) ### Create example matrix
cascades <- as_cascade_wide(df_matrix)

Then fit the model:

result <- netinf(cascades, quiet = TRUE, p_value_cutoff = 0.05)
head(result)
origin_node destination_node improvement p_value
20 7 290.1 7.324e-06
8 17 272 1.875e-05
3 2 270.5 1.87e-05
20 5 262.8 1.899e-05
7 16 250.4 4.779e-05
20 15 249 4.774e-05