data(Phuket)
# magnitudes are rounded to 1 dp
Phuket$magnitude <- Phuket$magnitude - 4.95
TT <- c(0, 1827)
params <- c(0.0001, 73, 1.3, 0.01, 1.0, 0.01)
etas_tmp <- function(data, evalpts, params, TT=NA, tplus=FALSE){
# etas_normal0 params = c(mu, A, alpha, c, p, dx, dy, beta)
# etas_tmp params = c(mu, A, alpha, c, p, d)
# want: d=dx=dy and alpha=beta
etas_normal0(data, evalpts, params=c(params, params[6], 0),
fixedparams=c(89, 105, -5, 16),
TT=TT, tplus=tplus)
}
x <- mpp(data=Phuket,
gif=etas_tmp,
marks=list(NULL, NULL),
params=params,
gmap=expression(params),
mmap=NULL,
TT=TT)
allmap <- function(y, p){
y$params <- exp(p)
return(y)
}
# Note: the "Not run" blocks below are not run during package checks
# as the makeSOCKcluster definition is specific to my network,
# modify accordingly if you want parallel processing.
cl <- NULL
if (require(snow)){
cl <- makeSOCKcluster(c("horoeka.localdomain", "horoeka.localdomain",
"kowhai.localdomain", "kowhai.localdomain",
"localhost", "localhost"))
clusterExport(cl, c("etas_normal0"))
}
initial <- log(params)
# set iterlim larger to converge satisfactorily
# needs about 47 iterations
z <- nlm(neglogLik, initial, object=x, pmap=allmap,
print.level=2, iterlim=1, SNOWcluster=cl)
if (!is.null(cl)){
stopCluster(cl)
rm(cl)
}
x <- allmap(x, z$estimate)
print(z$code)
print(x$params)
# MLE = (1.139316e-04 7.258019e+01 1.304519e+00 8.839539e-03
# 9.999858e-01 9.299687e-03)
print(logLik(x))
# -2954.28
# The integral term should be equal to the number
# of events in TT (1248)
print(sum((x$data$time > TT[1]) & (x$data$time < TT[2])))
print(etas_tmp(x$data, NULL, x$params, TT=TT))
Run the code above in your browser using DataLab