Skip to main content

Tools for simulating and analyzing the spillover between online and offline activities

Project description

Online–Offline Spillover

O2O is a Python package that quantifies mutual spillover between online and offline events, showing how activity in one arena can influence and be influenced by the other. Generating realistic synthetic data, it lets you prototype analyses before working with sensitive records. Using a bivariate Hawkes process, O2O delivers clear estimates of both the strength and direction of these reciprocal effects, whether you are examining social-media dynamics alongside real-world incidents or any other paired event streams.

Dependencies

To use O2O, make sure the following Python libraries are installed:

pip install numpy pandas matplotlib pystan nest_asyncio
  • The package was developed and tested with Python 3.9.5. I highly recommend installing Python and the required dependencies in a virtual environment such as Conda. On Unix-based systems (Linux, macOS), Python is often tied to critical system functions, so modifying the system-wide Python installation can be risky. To install Conda:

  • Visit the Miniconda download page and download the appropriate installer for your operating system.

  • Follow the installation instructions.

  • Once installed, create and activate a dedicated environment

conda create -n o2o_env python=3.9
conda activate o2o_env

Once your environment is activated, install the required dependencies.

  • Once you install all the dependencies, you can install the package using
pip install o2o-process
  • API documentation is provided in O2O_API_documentation.pdf in the docs directory.

Usage

You can use O2O in two ways:

  • From a Jupyter Notebook (demo.ipynb)
  • From the terminal using the Python script (demo.py)

When using demo.py, you will be prompted to specify:

  • The number of users
  • The time window of interest (in days)

The package performs the following:

1. Generates synthetic timestamp data

  • Simulates timestamps for both online and offline user events.

2. Estimates spillover effects

  • Calculates the influence of one event type (online/offline) on the other and its corresponding 95% confidence interval.
  • Decay rates and their 95% confidence intervals.
  • The percentage of events caused by the other type.
  • Estimates for the baseline intensities online and offline for each user as well as their corresponding 95% confidence interval.

3. Summarizes user activity

  • Computes the total number of online and offline events per user.
  • Plots the coupled online–offline intensity over time for each user.

Model

The model is a bivariate Hawkes process that can be described by the conditional intensities

$$ \lambda_1^{\text{user}} = \mu_1^{\text{user}} + \sum\limits_{k:t>t_k^1}^{N_\text{user}^1} \alpha_{11}\gamma_{11} e^{-\gamma_{11}(t-t_k^1)} + \sum\limits_{k:t>t_k^2}^{N^2_\text{user}} \alpha_{12}\gamma_{12} e^{-\gamma_{12}(t-t_k^2)} $$ $$ \lambda_2^{\text{user}} = \mu_2^{\text{user}} + \sum\limits_{k:t>t_k^1}^{N^1_\text{user}} \alpha_{21}\gamma_{21} e^{-\gamma_{21}(t-t_k^1)} + \sum\limits_{k:t>t_k^2}^{N^2_\text{user}} \alpha_{22}\gamma_{22} e^{-\gamma_{22}(t-t_k^2)}, $$

where:

  • Online activity (e.g., hostile posts) is indexed by 1.
  • Offline activity (e.g., shootings) is indexed by 2.
  • $\alpha_{ij}$: expected number of type-i events triggered by an initial type-j event.
  • $\gamma_{ij}$: decay rate of influence from type $j$ to type $i$
  • $\mu^{\text{user}} = [\mu_1, \mu_2]$: baseline intensities per user

Aknowledgement

This package is based on:

John Leverso, Youness Diouane, George Mohler, "Measuring Online–Offline Spillover of Gang Violence Using Bivariate Hawkes Processes", Journal of quantitative criminology, 2025.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

o2o_process-0.1.1.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

o2o_process-0.1.1-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file o2o_process-0.1.1.tar.gz.

File metadata

  • Download URL: o2o_process-0.1.1.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for o2o_process-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f51347bf3b213b1fe1c3f25899cb2ca80643f8b27eb2a32beb5c068d74f800df
MD5 f4ac22e9e4f5b36f049b150b984aa190
BLAKE2b-256 74993ff2ffc4e584e7c03ccc64af51db4e8ee6c6d71eb3031edaa2caab149ba0

See more details on using hashes here.

File details

Details for the file o2o_process-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: o2o_process-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for o2o_process-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a9621a5ab94af3cf7d7358f7bec7780ac986ac05206fdff85939876762d8539c
MD5 fe916c37917e3ed48c3c53213362e841
BLAKE2b-256 480489e39c607915cf3aa1c4465ec3ad00c6338f26abe283d482db385ce20113

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page