fit_series: Fit a Hawkes process or HawkesN process model on one or many...

View source: R/fit.R

fit_seriesR Documentation

Fit a Hawkes process or HawkesN process model on one or many event cascades and learn model parameters.

Description

Fit a Hawkes process or HawkesN process model on one or many event cascades and learn model parameters.

Usage

fit_series(
  data,
  model_type,
  cores = 1,
  init_pars = NULL,
  .init_no = NULL,
  observation_time = NULL,
  lower_bound = NULL,
  upper_bound = NULL,
  limit_event = NULL,
  model_vars = NULL,
  parallel_type = "PSOCK",
  ...
)

Arguments

data

A list of data.frame(s) where each data.frame is an event cascade with event tims and event magnitudes (optional)

model_type

A string representing the model type, e.g. EXP for Hawkes processes with an exponential kernel function

cores

The number of cores used for parallel fitting, defaults to 1 (non-parallel)

init_pars

A data.frame of initial parameters passed to the fitting program. Parameters should be aligned with required ones for the corresponding "model_type". The default initial parameters will be used if not provided.

.init_no

If initi_pars is not provided, currently 10 random starting parameters are generated for fitting. This controls which random points are used. Defaults to NULL

observation_time

The event cascades observation time(s). This can either be a single number indicating a common observation time for all cascades or a vector of observation times which has the same length as the number of cascades.

lower_bound

Model parameter lower bounds. A named vector where names are model parameters and values are the lowest possible values.

upper_bound

Model parameter upper bounds. A named vector where names are model parameters and values are the largest possible values.

limit_event

Define the way to optimize the computation by reducing the number of events added in log-likelihood (LL) functions, defaults to NULL, i.e., no optimization. To limit the number of events computed, a list with 'type' and 'value' shoud be provided. For example, limit_event = list(type = "event", value = 10) limits the LL fitting to 10 events, limit_event = list(type = "time", value = 10) limits the LL fitting to the events within past 10 time units. The best practice to trade-off the computation could be to limit to the largest number of events that one can afford.

model_vars

A named list of extra variables provided to hawkes objects

parallel_type

One of "PSOCK" or "FORK". Default to "PSOCK". See "Details" in makeCluster parallel.

...

Further arguments passed to ampl

Value

A model object where the [par] is fitted on [data]. [convergence] indicates the fitting convergence status and [value] is the negative log-likelihood value of the fitted model on [data].

Examples

## Not run: 
data <- generate_series(model_type = 'EXP',
                                     par = c(K = 0.9, theta = 1),
                                     sim_no = 10, Tmax = Inf)
fitted <- fit_series(data, 'EXP', observation_time = Inf)
fitted$par # fitted parameters
fitted$convergence # convergence status
fitted$value # negative log-likelihood value

## End(Not run)

behavioral-ds/evently documentation built on Feb. 3, 2023, 9:42 a.m.