linksrm_gif: Ground Intensity for Linked Stress Release Model

Description Usage Arguments Details Value Function Attributes Modify Function to Decrease Calculation Time References See Also

Description

Calculates the value of the ground intensity of a Linked Stress Release Model (LSRM). This model allows for multiple linked regions, where the stress can be transferred between the regions.

Usage

1
linksrm_gif(data, evalpts, params, TT=NA, tplus=FALSE, eta=0.75)

Arguments

data

a data frame containing the event history, where each row represents one event. There must be columns named "time", usually the number of days from some origin; "magnitude" which is the event magnitude less the magnitude threshold, i.e. Mk - M0; and "region" which are consecutively numbered starting at 1.

evalpts

a matrix or data.frame. It must include two columns named "time" and "region" that can be referred to as evalpts[,"time"] and evalpts[,"region"], respectively. The function will be evaluated at these points.

params

vector of parameters of length n^2+2n, where n is the number of regions, for the proposed LSRM in the following order:

(a_1, ..., a_n, b_1, ..., b_n, c_{11}, c_{12}, c_{13}, ..., c_{nn}).

TT

vector of length 2, being the time interval over which the integral of the ground intensity function is to be evaluated.

tplus

logical, lambda_g(t,i|Ht) is evaluated as lambda_g(t^+,i|Ht) if TRUE, else lambda_g(t^-,i|Ht).

eta

a scalar used in the stress calculations, see Details below.

Details

The ground intensity for the ith region is assumed to have the form

lambda_h(t,i) = exp{ a_i + b_i*[t - sum_j c_{ij} S_j(t)]}

with params = (a_1, ..., a_n, b_1, ..., b_n, c_{11}, c_{12}, c_{13}, ..., c_{nn}); and

S_j(t) = SUM_k 10^{eta(M_k-M_0)},

where the summation is taken over those events in region j with time t_k < t. This model has been discussed by Bebbington & Harte (2001, 2003). The default value of eta = 0.75.

Value

Two usages are as follows.

1
2
linksrm_gif(data, evalpts, params, tplus=FALSE, eta=0.75)
linksrm_gif(data, evalpts=NULL, params, TT, eta=0.75)

The first usage returns a vector containing the values of lambda_g(t,i) evaluated at the specified “time-region” points. In the second usage, it returns a vector containing the value of the integral for each region.

Function Attributes

rate

is "increasing".

regions

is expression(sqrt(length(params) + 1) - 1).

Modify Function to Decrease Calculation Time

The function linksrm_gif calculates the stress reduction matrices St1 and St2 every time that the function is called. Ideally, these should be calculated once and be included within the model object. Currently, the structure of the model object is not sufficiently flexible. However, the user can create a new function to calculate St1 and St2 once. This will only work if the event history is not changing between successive calls (e.g. parameter estimation). However, in a simulation, the history changes with the addition of each new event, and in this situation St1 and St2 need to be calculated with every function call.

The modified function, as described below, will write the objects St1 and St2 to a temporary database (position 2 in the search path). Consequently, it cannot be defined within the package itself because this violates the CRAN rules. The function linksrm_gif contains markers indicating the beginning and ending of the parts where St1 and St2 are calculated. The modified function is made by editing the function linksrm_gif. We firstly deparse the function linksrm_gif (i.e. put the contents into a character vector). We initially create a temporary database called PtProcess.tmp in which to write St1 and St2. We then search for the line numbers that mark the beginning and ending of the parts where St1 and St2 are calculated. We replace the beginning of each with a conditional statement so that the contents are only run if these two objects do not already exist. We then parse the lines of code in the character vector back into a function, and call this new function linksrm1_gif. The same thing can be achieved by dumping linksrm_gif to a text file and editing manually.

 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
#   define linksrm1_gif by modifying linksrm_gif

#   put function linksrm_gif into a character vector
tmp <- deparse(linksrm_gif)

#   remove "if (FALSE)" lines
linenum <- grep("if \(FALSE\)", tmp)
tmp <- tmp[-linenum]

#   attach new database at pos=2 in search path called PtProcess.tmp
linenum <- grep("attach new database to search path", tmp)
tmp[linenum] <- "if (!any(search()==\"PtProcess.tmp\")) attach(NULL,
                      pos=2L, name=\"PtProcess.tmp\", warn.conflicts=TRUE)"

#   calc St1 if St1 does not exist
linenum <- grep("this loop calculates St1", tmp)
tmp[linenum] <- "if (!exists(\"St1\", mode = \"numeric\")) {"
linenum <- grep("assign statement for St1", tmp)
tmp[linenum] <- "assign(\"St1\", St1, pos=\"PtProcess.tmp\")"
linenum <- grep("end loop St1", tmp)
tmp[linenum] <- "}"


#   calc St2 if St2 does not exist
linenum <- grep("this loop calculates St2", tmp)
tmp[linenum] <- "if (!exists(\"St2\", mode = \"numeric\")) {"
linenum <- grep("assign statement for St2", tmp)
tmp[linenum] <- "assign(\"St2\", St2, pos=\"PtProcess.tmp\")"
linenum <- grep("end loop St2", tmp)
tmp[linenum] <- "}"

linksrm1_gif <- eval(parse(text=tmp))

Warning: The function linksrm1_gif checks to see whether the matrices St1 and St2 exist. If so, these existing matrices are used, and new ones are not calculated. Therefore when using linksrm1_gif for parameter estimation, one must check for the existence of such matrices, and delete upon starting to fit a new model:

1
2
if (exists("St1")) rm(St1)
if (exists("St2")) rm(St2)

or detach the database as detach(2). The objects St1 and St2 will exist for the duration of the current R session, so should be deleted when no longer required.

References

Cited references are listed on the PtProcess manual page.

See Also

General details about the structure of ground intensity functions are given in the topic gif.


PtProcess documentation built on May 4, 2021, 1:06 a.m.