knitr::opts_chunk$set(echo = TRUE)
This is a minimal example of using the code in the hawkes
package. The package is in very preliminary stages of development. The main functions are illustrated here. See the documentation for a full list functions and issues.
First install and load the package.
devtools::install_github("peterhalpin/hawkes") library("hawkes")
It comes with an example dataset, email
, which is a list of two vectors containing the sendings times of email exchanges between an employer and employee. Time is recorded in hours and the employee's start date is t = 0
. See Halpin & DeBoeck (2013) for more details. The function pp
takes a list of event times and turns it into an S3 object with some basic functionality.
pp_obj <- pp(email) print(pp_obj) plot(pp_obj)
The gof
function can be used to visually inspect the data for temporal clustering (i.e., overdispersion relative to the homogeneous Poisson process). See help(gof)
for more details.
gof(pp_obj)
The clustering might be accounted for using the Hawkes process. To esimtate the model use the EM
function and see help(EM)
for a description. (This will take a while to run and the optim
trace output will print to the console. Using just a few iterations for this e.g.)
hawkes_em <- EM(pp_obj, nstarts = 1, maxit = 3)
Check out EM output:
hawkes_em
Use the get_parms
function to extract and format Solutions from EM
and then call the gof
function with the parms to assess whether the model accounted for the clustering in the data.
parms <- get_parms(hawkes_em) gof(pp_obj, parms)
Check back soon for data simulation, computation of standard errors, choice of response kernels, and other functionality currently under development.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.