knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "75%"
)

ppdiag

R build status CRAN status Lifecycle: stable Codecov test coverage DOI

ppdiag is an R package which provides a collection of tools which can be used to assess the fit of temporal point processes to data.

These currently include:

Installation

You can install the released version of ppdiag from CRAN with:

install.packages("ppdiag")

The current development version of this package is available from GitHub with:

# install.packages("remotes")
remotes::install_github("OwenWard/ppdiag")

Example

To illustrate some of the basic functionality of this package, we can simulate data from a specified Hawkes process and examine our diagnostic results when we fit a homogeneous Poisson process to this data.

library(ppdiag)

hp_obj <- pp_hp(lambda0 = 0.2, alpha = 0.35, beta = 0.8)
sim_hp <- pp_simulate(hp_obj, end = 200)
sim_hp

We can readily evaluate the fit of a homogeneous Poisson process to this data.

est_hpp <- fithpp(sim_hp)
est_hpp

pp_diag(est_hpp, events = sim_hp)
hp_est <- fithp(events = sim_hp)
pp_diag(hp_est, events = sim_hp)

Markov Modulated Hawkes Process Example

This is particularly useful for more complex point processes, such as the Markov Modulated Hawkes Process (MMHP). We can simulate events from this model and examine the fit of simpler point processes to this data.

Q <- matrix(c(-0.2, 0.2, 0.1, -0.1), ncol = 2, byrow = TRUE)

mmhp_obj <- pp_mmhp(Q, delta = c(1 / 3, 2 / 3), 
          lambda0 = 0.2,
          lambda1 = .75,
          alpha = 0.4,
          beta = 0.8)

mmhp_obj
mmhp_events <- pp_simulate(mmhp_obj, n = 50)

We can easily fit a homogeneous Poisson process and visualise the goodness of fit.

est_hpp <- fithpp(events = mmhp_events$events)
pp_diag(est_hpp,mmhp_events$events)

Similarly for a Hawkes process.

est_hp <- fithp(events = mmhp_events$events)
pp_diag(est_hp,mmhp_events$events)

We can then compare to the true point process model.

pp_diag(mmhp_obj, mmhp_events$events)

Getting help and contributing

Please file any issues here. Similarly, we would be delighted if anyone would like to contribute to this package (such as adding other point processes, kernel functions). Feel free to take a look here and reach out with any questions.

References



OwenWard/ppdiag documentation built on Feb. 19, 2023, 11:34 a.m.