`ppdiag`, diagnostic tools for temporal Point Processes"

  collapse = TRUE,
  comment = "#>"
set.seed(100) # to make it reproducible
# remotes::install_github("OwenWard/ppdiag")

This vignette provides an introduction to the functions available in ppdiag to evaluate the fit of univariate temporal point processes.

To achieve this, we currently include a range of functions which allow a user to:


We create classes for each of the point process models included in the package. Currently, these are:

pp_hpp(lambda) creates a hpp object with rate parameter lambda.

hpp_obj <- pp_hpp(lambda = 1)

pp_hp(lambda0, alpha, beta, events = NULL) creates a hp object.

hp_obj <- pp_hp(lambda0 = 0.5, alpha = 0.2, beta = 0.5)
Q <- matrix(c(-0.4, 0.4, 0.2, -0.2), ncol = 2, byrow = TRUE)

mmpp_obj <- pp_mmpp(Q, delta = c(1 / 3, 2 / 3), 
          lambda0 = 0.8,
          c = 1.2)


pp_mmhp(lambda0, lambda1, alpha, beta, Q, delta) creates an mmhp object.

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


Simulating data

To simulate data from a given point process, we use the function pp_simulate(pp_obj, ...). Here the first argument specifies one of the above point processes, while the remaining arguments specify either the number of events simulated or the length of the observation period for possible events.

For example, we can simulate events up to a specified end time.

hpp_events <- pp_simulate(hpp_obj, end = 10)

Alternatively, we can specify the number of events we wish to simulate.

hp_events <- pp_simulate(hp_obj, start = 0, n = 20)

This returns the simulated events of the specified point process. For Markov Modulated processes, the states (and the times of these states) are also returned. In this scenario only a specified number of events can be simulated (currently).

mmhp_events <- pp_simulate(object = mmhp_obj, n = 20)

Fitting a point process

For completeness, we include functions for fitting both homogeneous Poisson and Hawkes processes to data. Fitting a Markov modulated model is more complex, although we describe this procedure in an included vignette.

fithpp(hpp_events) returns an object of class hpp, estimating the MLE of a homogenous Poisson process for hpp_events

fit_hpp <- fithpp(hpp_events)

Similarly, fithp(hp_events) returns an object of class hp, estimating the three parameters of the Hawkes process from hp_events using constrOptim. This ensures that the returned solution (if one can be obtained), satisfies the stationary condition of a Hawkes process.

hp_events <- pp_simulate(hp_obj, n = 500)
fit_hp <- fithp(hp_events)

Diagnosing the fit of a point process to data

The main goal of this package is to provide users with tools to examine the fit of a specified point process to some data. There are several methods which can be used to assess the goodness of fit of a point process to temporal data. In this package we allow a user to:

Visualize the intensity function

drawHPPIntensity(hpp, events) plots the intensity of a homogeneous Poisson process.

drawHPPIntensity(fit_hpp, events = hpp_events,
                 color = "red")

Similarly, drawHPIntensity(hp, events) plots the intensity of a Hawkes process.

drawHPIntensity(fit_hp, events = hp_events)

To plot the fitted intensity on the input events, set fit=TRUE.

drawHPIntensity(events = hp_events, fit = TRUE)

Similarly, drawUniMMHPIntensity(mmhp, mmhp_events) plots the intensity of a Markov modulated Hawkes process, with a similar function for Markov modulated Poisson processes. This requires both the point process object and the output from pp_simulate which describes the latent process.

drawUniMMHPIntensity(mmhp_obj, mmhp_events)

Visualize intensity and goodness of fit jointly

intensityqqplot(object = fit_hp, events = hp_events )
# this gives an error currently
intensityqqplot(object = mmhp_obj, markov_states = mmhp_events)

Residual Analysis

pp_residual(object = mmhp_obj, events = mmhp_events$events)

pp_residual(object = fit_hp, events = hp_events)

Overall summary of fit

pp_diag(object = fit_hp, events = hp_events)

Try the ppdiag package in your browser

Any scripts or data that you put into this service are public.

ppdiag documentation built on Aug. 12, 2021, 5:07 p.m.