hfit: Perform Maximum Likelihood Estimation

Description Usage Arguments See Also Examples

Description

Generic function hfit. Exponential decaying marked A method for estimating the parameters of the Hawkes model. The reason for being constructed as the S4 methodis as follows. First, to represent the structure of the model as an hspec object. There are numerous variations on the mutlivariate marked Hawkes model. Second, to convey the starting point of numerical optimization. The parameter values assigned to the hspec slots become initial values. This function uses maxLik for the optimizer.

This function uses maxLik for the optimizer.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
hfit(object, inter_arrival = NULL, type = NULL, mark = NULL, N = NULL,
  Nc = NULL, lambda0 = NULL, N0 = NULL, mylogLik = NULL,
  reduced = TRUE, grad = NULL, hess = NULL, constraint = NULL,
  method = "BFGS", verbose = FALSE, ...)

## S4 method for signature 'hspec'
hfit(object, inter_arrival = NULL, type = NULL,
  mark = NULL, N = NULL, Nc = NULL, lambda0 = NULL, N0 = NULL,
  mylogLik = NULL, reduced = TRUE, grad = NULL, hess = NULL,
  constraint = NULL, method = "BFGS", verbose = FALSE, ...)

Arguments

object

hspec-class. This object includes the parameter values

inter_arrival

inter-arrival times of events. Includes inter-arrival for events that occur in all dimensions. Start with zero.

type

a vector of dimensions. Distinguished by numbers, 1, 2, 3, and so on. Start with zero.

mark

a vector of mark (jump) sizes. Start with zero.

lambda0

the inital values of lambda component. Must have the same dimensional matrix (n by n) with hspec.

N0

the initial values of N.

mylogLik

user defined log likelihood function. mylogLik function should have 'object' argument, cosistent with hspec.

reduced

When TRUE, reduced estimation performed.

grad

gradient matrix for the likelihood function. For more information, see maxLik.

hess

Hessian matrix for the likelihood function. For more information, see maxLik.

constraint

constraint matrix. For more information, see maxLik.

method

method for optimization. For more information, see maxLik.

verbose

If TRUE, print the progress of the estimation.

...

other parameters for optimization. For more information, see maxLik.

See Also

hspec-class, hsim,hspec-method

Examples

 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
# example 1
mu <- c(0.1, 0.1)
alpha <- matrix(c(0.2, 0.1, 0.1, 0.2), nrow=2, byrow=TRUE)
beta <- matrix(c(0.9, 0.9, 0.9, 0.9), nrow=2, byrow=TRUE)
h <- new("hspec", mu=mu, alpha=alpha, beta=beta)
res <- hsim(h, size=100)
summary(hfit(h, res$inter_arrival, res$type))


# example 2

mu <- matrix(c(0.08, 0.08, 0.05, 0.05), nrow = 4)
alpha <- function(param = c(alpha11 = 0, alpha12 = 0.4, alpha33 = 0.5, alpha34 = 0.3)){
  matrix(c(param["alpha11"], param["alpha12"], 0, 0,
           param["alpha12"], param["alpha11"], 0, 0,
           0, 0, param["alpha33"], param["alpha34"],
           0, 0, param["alpha34"], param["alpha33"]), nrow = 4, byrow = TRUE)
}
beta <- matrix(c(rep(0.6, 8), rep(1.2, 8)), nrow = 4, byrow = TRUE)

impact <- function(param = c(alpha1n=0, alpha1w=0.2, alpha2n=0.001, alpha2w=0.1),
                   n=n, N=N, ...){

  Psi <- matrix(c(0, 0, param['alpha1w'], param['alpha1n'],
                  0, 0, param['alpha1n'], param['alpha1w'],
                  param['alpha2w'], param['alpha2n'], 0, 0,
                  param['alpha2n'], param['alpha2w'], 0, 0), nrow=4, byrow=TRUE)

  ind <- N[,"N1"][n] - N[,"N2"][n] > N[,"N3"][n] - N[,"N4"][n] + 0.5

  km <- matrix(c(!ind, !ind, !ind, !ind,
                 ind, ind, ind, ind,
                 ind, ind, ind, ind,
                 !ind, !ind, !ind, !ind), nrow = 4, byrow = TRUE)

  km * Psi
}
h <- new("hspec",
         mu = mu, alpha = alpha, beta = beta, impact = impact)
hr <- hsim(h, size=100)
plot(hr$arrival, hr$N[,'N1'] - hr$N[,'N2'], type='s')
lines(hr$N[,'N3'] - hr$N[,'N4'], type='s', col='red')
fit <- hfit(h, hr$inter_arrival, hr$type)
summary(fit)


# example 3

mu <- c(0.15, 0.15)
alpha <- matrix(c(0.75, 0.6, 0.6, 0.75), nrow=2, byrow=TRUE)
beta <- matrix(c(2.6, 2.6, 2.6, 2.6), nrow=2, byrow=TRUE)
rmark <- function(param = c(p=0.65), ...){
  rgeom(1, p=param[1]) + 1
}
impact <- function(param = c(eta1=0.2), alpha, n, mark, ...){
  ma <- matrix(rep(mark[n]-1, 4), nrow = 2)
  alpha * ma * matrix( rep(param["eta1"], 4), nrow=2)
}
h1 <- new("hspec", mu=mu, alpha=alpha, beta=beta,
          rmark = rmark,
          impact=impact)
res <- hsim(h1, size=100, lambda0 = matrix(rep(0.1,4), nrow=2))

fit <- hfit(h1,
            inter_arrival = res$inter_arrival,
            type = res$type,
            mark = res$mark,
            lambda0 = matrix(rep(0.1,4), nrow=2))
summary(fit)

# For more information, please see vignettes.

ksublee/emhawkes documentation built on April 18, 2019, 9:46 a.m.