# NOT RUN {
## earthquake times over 96 years
data(quake);
tms <- sort(quake$time);
# add some random noise to the simultaneous occurring event times
tms[213:214] <- tms[213:214] +
sort(c(runif(1, -1, 1)/(24*60), runif(1, -1, 1)/(24*60)))
## calculate the minus loglikelihood of an RHawkes with some parameters
## the default hazard function and density functions are Weibull and
## exponential respectively
mllRH(tms, cens = 96*365.25 , par = c(0.5, 20, 1000, 0.5))
damllRH(tms, cens = 96*365.25 , par = c(0.5, 20, 1000, 0.5),q=1,qe=1)
## calculate the MLE for the parameter assuming known parametric forms
## of the immigrant hazard function and offspring density functions.
system.time(est <- optim(c(0.5, 20, 1000, 0.5),
mllRH, tms = tms, cens = 96*365.25,
mu.fn=function(x,p)p[1]/p[2]*(x/p[2])^(p[1]-1),
Mu.fn=function(x,p)(x/p[2])^p[1],
control = list(maxit = 5000, trace = TRUE),
hessian = TRUE)
)
system.time(est1 <- optim(c(0.5, 20, 1000, 0.5),
function(p){
if(any(p<0)||p[4]<0||p[4]>=1)
return(Inf);
damllRH(tms = tms, cens = 96*365.25,
mu.fn=function(x,p)p[1]/p[2]*(x/p[2])^(p[1]-1),
Mu.fn=function(x,p)(x/p[2])^p[1],
par=p,q=0.999999,qe=0.999999)
},
control = list(maxit = 5000, trace = TRUE),
hessian = TRUE)
)
## point estimate by MLE
est$par
est1$par
## standard error estimates:
diag(solve(est$hessian))^0.5
diag(solve(est1$hessian))^0.5
# }
Run the code above in your browser using DataLab