Skip to contents

Companion to the Markovian exponential / constant fit in morie_tps_hawkes_temporal_fit. Supports the four kernels (exponential, gamma, Weibull, Lomax) and two baselines (constant, sinusoidal) of Kwan-Chen-Dunsmuir (2024).

Usage

morie_tps_hawkes_advanced_fit(
  df,
  kernel = "gamma",
  baseline = "sinusoidal",
  ds_name = "?",
  max_n = NULL,
  method = "auto",
  eps = 1e-09
)

Arguments

df

A data frame with an OCC_DATE or REPORT_DATE column.

kernel

Excitation kernel: one of "exponential", "gamma", "weibull", "lomax".

baseline

Baseline kind: "constant" or "sinusoidal".

ds_name

Dataset name used in titles and warnings.

max_n

Maximum number of events to retain; NULL (the default) keeps every event. A subsample thins the process (and its clustering), so it is for quick looks only; it is the same subsample as morie's Python (splitmix64 keys).

method

Likelihood route: "auto", "exact", "soe", "truncate", "em" or "inar" (see Details).

eps

Error level of "soe" and "truncate".

Value

A morie_rich_result with branching ratio, stationarity verdict, kernel and baseline parameters, negative log-likelihood, AIC, BIC, and time-rescaling KS statistic.

Details

The fit is rmoriebricklayer's core_hawkes_fit() (the C++ routine morie's Python fit_hawkes_general calls): maximum likelihood with the analytic gradient by projected BFGS under box constraints, from the default start and from the exponential fit. method chooses how the likelihood is evaluated: "exact" (Ozaki's O(n) recursion for the exponential kernel; for Weibull and gamma the double sum stops where the kernel underflows to 0), "soe" (Lomax, and gamma with shape < 1, as a sum of exponentials with relative error eps), "truncate" (kernel tail mass below eps left out), "em" (the EM algorithm) or "inar" (Kirchner's INAR estimator, constant baseline); "auto" is "exact" for the exponential kernel, "truncate" for Weibull and "soe" for Lomax and gamma.

Goodness-of-fit is reported via time-rescaling residuals (Brown et al. 2002) and a Kolmogorov-Smirnov test against Uniform(0, 1).

References

Kwan TKJ, Chen F, Dunsmuir WTM (2024). Likelihood inference for non-stationary Hawkes processes. arXiv:2408.09710v1.

Examples

# \donttest{
  df <- morie_tps_load_tps_dataset("Assault", nrows = 400)
#> morie_tps: no local TPS cache for 'Assault'; using the bundled sample from rmoriedata. Fetch the full export with morie_tps_fetch_category().
  rr <- morie_tps_hawkes_advanced_fit(df, kernel = "gamma",
                                        baseline = "sinusoidal",
                                        ds_name = "Assault")
  print(rr$summary_lines)
#> $events_fitted
#> [1] 394
#> 
#> $time_window_days
#> [1] 4428.2
#> 
#> $kernel
#> [1] "gamma"
#> 
#> $baseline
#> [1] "sinusoidal"
#> 
#> $branching_ratio
#> [1] 0.0497
#> 
#> $stationary
#> [1] "Yes (eta<1)"
#> 
#> $kernel_params
#> [1] 15.0000  3.5117
#> 
#> $baseline_params
#> [1] -2.5577  0.1513  0.1053 -0.1988
#> 
#> $neg_log_likelihood
#> [1] 1340.7
#> 
#> $aic
#> [1] 2695.5
#> 
#> $bic
#> [1] 2723.3
#> 
#> $ks_stat
#> [1] 0.0286
#> 
#> $ks_pvalue
#> [1] 0.8939
#> 
# }