-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.Rmd
142 lines (102 loc) · 4.01 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "75%"
)
```
# ppdiag
<!-- badges: start -->
[![R build status](https://github.com/OwenWard/ppdiag/workflows/R-CMD-check/badge.svg)](https://github.com/OwenWard/ppdiag/actions)
[![CRAN status](https://www.r-pkg.org/badges/version/ppdiag)](https://CRAN.R-project.org/package=ppdiag)
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html)
[![Codecov test coverage](https://codecov.io/gh/OwenWard/ppdiag/branch/main/graph/badge.svg)](https://codecov.io/gh/OwenWard/ppdiag?branch=main)
[![DOI](https://joss.theoj.org/papers/10.21105/joss.03133/status.svg)](https://doi.org/10.21105/joss.03133)
<!-- badges: end -->
``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:
- Simulating data from a specified point process
- Fitting a specified point process model to data
- Evaluating the fit of a point process model to data using
several diagnostic tools
# Installation
You can install the released version of ppdiag from [CRAN](https://CRAN.R-project.org) with:
```{r, eval=FALSE}
install.packages("ppdiag")
```
The current development version of this
package is available from [GitHub](https://github.com/OwenWard/ppdiag) with:
```{r, eval=FALSE}
# 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.
```{r example}
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.
```{r fit_hpp}
est_hpp <- fithpp(sim_hp)
est_hpp
pp_diag(est_hpp, events = sim_hp)
```
```{r fit_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.
```{r mmhp example}
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.
```{r fit_hpp_to_mmhp}
est_hpp <- fithpp(events = mmhp_events$events)
pp_diag(est_hpp,mmhp_events$events)
```
Similarly for a Hawkes process.
```{r fit_hp_to_mmhp}
est_hp <- fithp(events = mmhp_events$events)
pp_diag(est_hp,mmhp_events$events)
```
We can then compare to the true point process model.
```{r fit_mmhp}
pp_diag(mmhp_obj, mmhp_events$events)
```
# Getting help and contributing
Please file any issues [here](https://github.com/OwenWard/ppdiag/issues).
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](https://github.com/OwenWard/ppdiag/blob/main/CONTRIBUTING.md)
and reach out with any questions.
# References
- Sun et al., (2021). ppdiag: Diagnostic Tools for Temporal Point Processes. Journal of Open Source Software, 6(61), 3133, https://doi.org/10.21105/joss.03133
- Wu et al. (2021), Diagnostics and Visualization of Point Process Models for Event Times on a Social Network,
In Applied Modeling Techniques and Data Analysis 1 (eds Y. Dimotikalis, A. Karagrigoriou, C. Parpoula and C.H. Skiadas).
https://doi.org/10.1002/9781119821588.ch7