knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) set.seed(100) # to make it reproducible
# remotes::install_github("OwenWard/ppdiag") library(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
hpp_obj <- pp_hpp(lambda = 1) hpp_obj
pp_hp(lambda0, alpha, beta, events = NULL) creates a
hp_obj <- pp_hp(lambda0 = 0.5, alpha = 0.2, beta = 0.5) hp_obj
pp_mmpp(lambda0, lambda1, alpha, beta, Q, delta)creates an
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) mmpp_obj
pp_mmhp(lambda0, lambda1, alpha, beta, Q, delta) creates an
mmhp_obj <- pp_mmhp(Q, delta = c(1 / 3, 2 / 3), lambda0 = 0.2, lambda1 = .75, alpha = 0.1, beta = 0.2) mmhp_obj
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
For example, we can simulate events up to a specified end time.
hpp_events <- pp_simulate(hpp_obj, end = 10) hpp_events
Alternatively, we can specify the number of events we wish to simulate.
hp_events <- pp_simulate(hp_obj, start = 0, n = 20) hp_events
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) mmhp_events
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
fit_hpp <- fithpp(hpp_events) fit_hpp
fithp(hp_events) returns an object of class
estimating the three parameters of the Hawkes process from
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) fit_hp$lambda0 fit_hp$alpha fit_hp$beta
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:
plots the intensity of a homogeneous Poisson process.
drawHPPIntensity(fit_hpp, events = hpp_events, color = "red")
plots the intensity of a Hawkes process.
drawHPIntensity(fit_hp, events = hp_events)
To plot the fitted intensity on the input events, set
drawHPIntensity(events = hp_events, fit = TRUE)
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.
intensityqqplotdisplays the estimated intensity of a given point process along with a QQ-plot of the rescaled inter-event times. These together can often be useful in identifying issues with model fit for a chosen point process.
intensityqqplot(object = fit_hp, events = hp_events )
# this gives an error currently intensityqqplot(object = mmhp_obj, markov_states = mmhp_events)
pp_residualreturns both raw and Pearson residuals from fitting the specified point process to the given events.
pp_residual(object = mmhp_obj, events = mmhp_events$events) pp_residual(object = fit_hp, events = hp_events)
pp_diagsummarises (both graphically and numerically) the fit of a specified point process to the data. For a given point process it computes the residuals (both raw and Pearson) obtained from fitting that point process to the data, performs a goodness of fit test based on the rescaled inter-event times, and displays graphical summaries of this diagnostic.
pp_diag(object = fit_hp, events = hp_events)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.