Bayesian estimation of ETAS models using Rstan (applied to seismic recurrence in Ecuador 2016) PhD student Applied Mathematics Fausto Fabian Crespo Fernández1 , PhD Statistics Carlos Jimenez Mosquera 1 1 San Francisco de Quito University(USFQ) StanCon2018 Introduction There were four mega earthquakes in the Ecuadorian Coast in the past century: I 1906(magnitude 8.8) I 1942(magnitude 7.8) I 1958(magnitude 7.7) I 1979(magnitude 8.2) And then... April 16th, 2016 a quake of magnitude 7.8 according to USGS (magnitude 7.4 according to Seismology Institute - EPN) Methods Omori law The empirical law of Omori and the law of Omori-Utsu (also called Modified Law of Omori) Utsu1995 describe the decreasing frequency of aftershocks over time after an earthquake: N(t) = K (t + c) (1) N(t) = K (t + c)p (2) Where N(t) is the occurrence rate of events, t is the time since the earthquake and K , c, p are constants. Methods Gutenberg-Ritcher law ... relates the magnitude to the number of earthquakes with magnitudes greater than M: log10 N(≥ M) = a − bM (3) That is, the number of events of magnitude greater than a threshold, decreases exponentially with the increase of that threshold value by a power law. So, the distribution of magnitudes by the Gutenberg-Richter law s(m) = βe −βm Gutenberg-Richter law Gutenberg-Richter law: linear regression log (N) = a + bM and then a = 5.064(sd = 0.039) and −0.694(sd = 0.007). From these values, b is 0.694 and β = bln(10) = 1.598. Methods An earthquake T is represented by a tuple (xi , yi , zi , Mi ) Temporal ETAS model The simplest ETAS model is the temporal model with constant P (p−1)c p−1 background seismicity: λ(t|Ht ) = µ + j:tj <t K(t−t p j +c) where µ is the background intensity that is assumed to be constant (measured in events / day) and g (t) = (p − 1)c p−1 (t + c)p (4) is the probability density function of the occurrence times of the events triggered by previous earthquakes. Methods Temporal ETAS model If the background intensity is not constant, but depends only on the longitude and latitude x, y we have: P (p−1)c p−1 λ(t|Ht ) = µ(x, y ) + j:tj <t K(t−t p j +c) where µ(x, y ) is now measured in events per day per unit of longitude and per unit of latitude. In this case, it is generally assumed that µ(x, y ) = µu(x, y ) where µ on the right side is a constant. Methods ETAS model with magnitudes Considering the magnitudes of earthquakes we have the model λ(t|Ht ) = µ + α(Mj −M0 ) P K (p−1)c p−1 Ae j:tj <t (t−tj +c)p Methods ETAS models stability The event rate in the ETAS models may explode. Stability depends on the branching ratio n =expected number of descendants of a R ∞ R Mmax parent event. We have n= 0 dt M0 s(m)λ(t)dm with s(m) = βe −βm the distribution of magnitudes by the GutenbergRichter law and λ(t) the branching term. For the temporal ETAS model with magnitudes and p > 1 we have Kc 1−p β 1−e −(β−α)(Mmax −M0 ) n = (p−1)(β−α) 1−e −β(Mmax −M0 ) Methods For the temporal ETAS model with magnitudes and p > 1 we have Kc 1−p β 1−e −(β−α)(Mmax −M0 ) n = (p−1)(β−α) Assuming Mmax = ∞ the 1−e −β(Mmax −M0 ) previous formula can be reduced to: n = Sornette2005 y Touati2011 and n is infinite if p < 1 or if α > β. Kc 1−p β (p−1)(β−α) Methods ETAS models stability If each event induces another event: n = 1 then the process propagates indefinitely. This justifies normalizing the functions that in the sum over the preceding events. For example R ∞ appear K dt = 1 implies that we need to add (p − 1)c p−1 to the p 0 (t+c) RM constant K and similarly M0max βe −β(m) dm = 1 implies we need to add 1/(exp(−βM0 ) − exp(−βMmax )) to the constant β . Methods RT P For temporal models: logL(θ) = j log λ(tj |Ht ) − 0 max λ(t)dt The closed forms for temporal and temporal with magnitudes models: logL(µ, k, p, c) = PN PN c p−1 i=1 log (λ(ti )) − µTmax − k i=1 (1 − (Tmax −ti +c)p−1 ) P logL(µ, k, p, c, A, α) = N i=1 log (λ(ti )) − µTmax − PN α(M −M0 ) c p−1 i kA i=1 e (1 − (Tmax −t ) +c)p−1 i Listing 1: Temporal Rstan model 24 with constant background seis25 26 micity 27 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 28 29 functions{ r e a l l o g l i k e l i h o o d ( i n t N, 30 r e a l mu , 31 real k , 32 real p , 33 real c , v e c t o r t i m e s d i f f34 35 , 36 r e a l tmax ) { 37 r e a l s e i s m i c r a t e [N ] ; 38 r e a l i n t e g r a l o f r a t e [N ] ; 39 real integral mu ; 40 real log likelihood ; 41 s e i s m i c r a t e [ N ]=l o g (mu) ; 42 i n t e g r a l o f r a t e [ N ]=0 ; 43 f o r ( j i n 1 : ( N−1) ) { 44 v e c t o r [ N−j ] y ; 45 int start ; 46 i n t end ; s t a r t =N∗( j −1)−( j ∗( j −1) ) /2 + 1 ; 47 48 end =j ∗N−( j ∗( j +1) ) / 2 ; 49 y=t i m e s d i f f [ s t a r t : end ] ; y=( k ∗( p − 1 ) ∗ c ˆ ( p−1) ) ∗exp(−p∗ 50 l o g ( y+c ) ) ; s e i s m i c r a t e [ j ]=l o g (mu+sum ( y ) ) ; 51 i n t e g r a l o f r a t e [ j ]=( k ) ∗(1−c ˆ ( p −1)/ ( ( t i m e s d i f f [ j ]+ c ) ˆ ( p−1) ) ) ; } i n t e g r a l m u=mu∗tmax ; l o g l i k e l i h o o d=sum ( s e i s m i c r a t e )− i n t e g r a l m u −sum ( integral of rate ) ; return ( l o g l i k e l i h o o d ) ; } } data{ i n t <l o w e r=0> N ; r e a l <l o w e r=0> m a x t i m e ; v e c t o r [ N∗(N−1) / 2 ] t i m e s d i f f ; } parameters{ r e a l <l o w e r=0> mu ; r e a l <l o w e r=0> k ; r e a l <l o w e r=1.000005 > p ; r e a l <l o w e r=0.00005 > c ; } model{ mu˜ e x p o n e n t i a l ( 2 . 8 ) ; k˜ e x p o n e n t i a l ( 2 . 8 ) ; p˜ e x p o n e n t i a l ( 0 . 3 ) ; c˜ e x p o n e n t i a l ( 2 . 8 ) ; i n c r e m e n t l o g p r o b ( l o g l i k e l i h o o d (N, mu ,k, p , c , t i m e s d i f f , max time ) ) ; } Listing 2: Temporal with magni29 30 tudes Rstan model with constant 31 background seismicity 32 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 33 functions{ 34 r e a l l o g l i k e l i h o o d ( i n t N, 35 r e a l mu , 36 real k , 37 real p , 38 real c , r e a l alpha , 39 r e a l A, 40 vector t , 41 v e c t o r m a g n i t u d e s42 , 43 v e c t o r t i m e s d i f f44 , 45 r e a l max time , 46 r e a l magnitude0 ){ 47 r e a l s e i s m i c r a t e [N ] ; 48 r e a l i n t e g r a l o f r a t e [N ] ; 49 real integral mu ; 50 real log likelihood ; 51 s e i s m i c r a t e [ N ]= l o g (mu) ; 52 i n t e g r a l o f r a t e [ N ]=0 ; 53 f o r ( j i n 1 : ( N−1) ) { 54 v e c t o r [ N−j ] y ; 55 int start ; 56 i n t end ; 57 s t a r t = N∗( j − 1 )−( j ∗( j −1) ) /2 +58 1; 59 end =j ∗N−( j ∗( j +1) ) / 2 ; 60 y=t i m e s d i f f [ s t a r t : end ] ; 61 y=( k∗A∗( p−1)∗c ˆ ( p−1) ) ∗exp ( a l p h a ∗ 62 ( m a g n i t u d e s [ ( j +1) :] − 63 magnitude0 ) ) . ∗ exp(−p∗ l o g ( y+c ) ) ; s e i s m i c r a t e [ j ]=l o g (mu+sum ( y ) ) ; i n t e g r a l o f r a t e [ j ]=( k∗A) ∗exp ( alpha∗ ( m a g n i t u d e s [ j +1]− m a g n i t u d e 0 ) ) ∗(1−c ˆ ( p−1)/ ( ( t i m e s d i f f [ j ]+ c ) ˆ ( p−1) ) ) ; } i n t e g r a l m u =mu∗ m a x t i m e ; l o g l i k e l i h o o d=sum ( s e i s m i c r a t e )− i n t e g r a l m u −sum ( i n t e g r a l o f r a t e ); return ( l o g l i k e l i h o o d ) ; } } data{ i n t <l o w e r=0> N ; v e c t o r [N] times ; r e a l <l o w e r=0> m a x t i m e ; v e c t o r [N] magnitudes ; v e c t o r [ N∗(N−1) / 2 ] t i m e s d i f f ; r e a l <l o w e r=0> t h r e s h o l d m a g n i t u d e ; } parameters{ r e a l <l o w e r=0> mu ; r e a l <l o w e r=0> k ; r e a l <l o w e r=1.000005 > p ; r e a l <l o w e r=0.00005 > c ; r e a l <l o w e r=0> a l p h a ; r e a l <l o w e r=0> A ; } model{ mu˜ e x p o n e n t i a l ( 2 . 8 ) ; k˜ e x p o n e n t i a l ( 2 . 8 ) ; p˜ e x p o n e n t i a l ( 0 . 3 ) ; c˜ e x p o n e n t i a l ( 2 . 8 ) ; alpha ˜ exponential (2.8) ; 64 65 66 A˜ e x p o n e n t i a l ( 2 . 8 ) ; i n c r e m e n t l o g p r o b ( l o g l i k e l i h o o d (N, 67 mu , k , p , c 68 , alpha , A, times , magnitudes , t i m e s d i f f , max time , t h r e s h o l d m a g n i t u d e ) ) ; } Methods Isotropic spatio temporal ETAS model In 1998 Ogata proposed a modified version of the spatio-temporal ETAS model: P λ(t, x, y ) = µ + j:tj <t g (t − tj , x − xj , y − yj , Mj |Ht ) where α(M−M ) x 2 +y 2 g (t, x, y , M) Ke(t+c)p 0 { e γ(M−M + d}−q and the background 0) intensity µ is constant. We can normalize: g (t, x, y , M) = K (p−1)c p−1 (q−1)d q−1 αe (α−γ)(M−M0 ) x 2 +y 2 { e γ(M−M π(t+c)p 0) + d}−q Methods Anisotropic spatio temporal ETAS model λ(t, x, y ) = µ + P j:tj <t where g (t, x, y , M) = g (t − tj , x − xj , y − yj , Mj |Ht ) pSj p T Ke α(M−M0 (t+c)p { e α(Mj −M0 ) + d}−q and p = (x − xj , y − yj ) is a row vector, xj , yj are the coordinates of the earthquake j preceding the earthquake with epicenter x, y (both in the same cluster) and Sj (j = 1, 2, ...) are positive definite symmetric matrices representing the normalized covariance matrix of the earthquake cluster obtained by applying MBC or Magnitude Based Cluster algorithm Methods Magnitude Based Cluster MBC This method is based on selecting the greatest magnitude earthquake(with magnitude Mj ) between those that are not in any cluster yet (if there are two with equal magnitude the oldest one is chosen) and then the earthquakes of the cluster associated with the previous selected earthquake, are those with latitude and longitude ± 3.33 ∗ 100.5Mj −2 km (Utsu spatial distance) from the latitude and longitude of the selected earthquake and with a time difference therefrom (towards the future) of max(100, 100.5Mj −1 ) days Ogata1998. Then the process is repeated with earthquakes that are not yet in any cluster until all earthquakes belong to a cluster. Bivariate normal distribution For the anisotropic normal bivariate models model, 2 four x1 σ̃ 0 Ogata1998: N( , ) y 0 σ̃ 2 2 1 x̄ σ̂ 0 N( , ) ȳ 0 σ̂ 2 x1 σ˜1 2 ρ̃σ˜1 σ˜2 N( , ) y ρ̃σ˜ σ˜ σ˜2 2 1 12 2 x̄ σˆ1 ρ̂σˆ1 σˆ2 N( , ) ȳ ρ̂σˆ1 σˆ2 σˆ2 2 x σ˜1 2 ρ̃σ˜1 σ˜2 N( 1 , ) y ρ̃σ˜ σ˜ σ˜2 2 1 12 2 x̄ σˆ1 ρ̂σˆ1 σˆ2 N( , ) ȳ ρ̂σˆ1 σˆ2 σˆ2 2 where (x1 , y1 ) is the position of the cluster’s main earthquake, (x̄, ȳ ) and centroid of the cluster. (Ogata 1998) Bivariate normal distribution P P And σ̃ 2 = [ j (xj − x1 )2 + j (yj − y1 )2 ]/(2n) P P σ̂ 2 = [ j (xj − x̄)2 + j (yj − ȳ )2 ]/(2n) P P σ˜1 2 =P[ j (xj − x1 )2 ]/n σ˜2 2 = [ j (yj − y1 )2 ]/n ρ̃ = [ j (xj − x1 )(yj − y1 )]/(nσ˜1 σ˜2 ) P σ˜1 2 = [ j (xj − x1 )2 ]/n P P σ˜2 2 = [ j (yj − y1 )2 ]/n ρ̃ = [ j (xj − x1 )(yj − y1 )]/(nσ˜1 σ˜2 ) P σˆ1 2 = [ j (xj − x̄)2 ]/n P σˆ2 2 =P[ j (yj − ȳ )2 ]/n ρ̂ = [ j (xj − x̄)(yj − ȳ )]/(nσˆ1 σˆ2 ) (Ogata 1998) Methods Bivariate normal We select the model with the lowest AIC = −nln(det(S))+2k where S is the variance covariance matrix for each of the four models and k is the corresponding number of parameters. Ogata1998. Then the selected matrix isnormalized: σ /σ −ρ 2 1 (√ 1 2 ) (1−ρ ) −ρ σ1 /σ2 Methods Hypocentral ETAS model Guo2015 introduces a modification of the spatio temporal ETAS model that includes P the depths of earthquakes λ(t, x, y ) = µ + j:tj <t g (t − tj , x − xj , y − yj , Mj |Ht ) where g (t, x, y , M) = z 0 h(z, z ) = 0 pSj p T Ke α(M−M0 (t+c)p { e α(Mj −M0 ) + d}−q h(z − zi , zi ) and 0 z ) ( Zz )η Z (1− Zz )η(1− Z 0 0 ZB(η zZ +1,η(1− zZ )+1) with Z theRthickness of the seismogenic layer and 1 B(p, q) = 0 t p−1 (1 − t)q−1 is the Beta function. Methods For spatio P temporal models RT R R logL(θ) = j log λ(tj , xj , yj |Ht ) − 0 max S λ(t, x, y )dxdydt For the hypocentral ETAS model, the logarithm of the likelihood is RT R R RZ P logL(θ) = j log λ(tj , xj , yj |Ht ) − 0 max S 0 λ(t, x, y )dzdxdydt In spatio temporals models, the log likelihood does not have a closed form. Methods We approximate the log likelihood for spatio temporals models using polar coordinates and S the minimum covering circle Minimum Covering Circle Welzl 1991 a b Methods(Cont) Approximation logL(µ, P k, p, c, d, α, γ) ≈ N log (λ(ti )) − µTmax πr 2 − Pi=1 c p−1 α(Mi −M0 ) (1 − )(1 − kα N i=1 e (Tmax −t +c)p−1 i d q−1 r2 ( α(M i−M ) +d)q−1 0 i e ) where r is the radius of the minimum covering circle, ri is the greatest distance between earthquake i and the previous earthquakes according to the metric defined in the cluster. Methods For the anisotropic model, the Euclidean distance is changed by the metric defined by the standardized variance covariance matrix Sj where now ri is calculated as the maximum distance (according to the previous metric) between each earthquake and the previous earthquakes in the cluster. Methods Pre-processing We sorted the data in reverse chronological time and calculated the time, latitude, and longitude differences for each earthquake j for which we know the initial and final positions where the differences of its time, latitude, and longitude with respect to the previous earthquakes are: start = N ∗ (j − 1) − (j ∗ (j − 1))/2 + 1 end = j ∗ N − (j ∗ (j + 1))/2 Listing 3: Anisotropic spatio26 27 temporal Rstan model with con28 29 stant background seismicity 30 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 r e a l s e i s m i c r a t e [N ] ; r e a l i n t e g r a l o f r a t e [N ] ; real integral mu ; real log likelihood ; s e i s m i c r a t e [ N ]=l o g (mu) ; 31 i n t e g r a l o f r a t e [ N ]=0 ; functions{ 32 f o r ( j i n 1 : ( N−1) ) { r e a l l o g l i k e l i h o o d ( i n t N, 33 v e c t o r [ N−j ] y ; r e a l mu , 34 v e c t o r [ N−j ] z ; real k , 35 v e c t o r [ N−1] x ; real p , 36 r e a l temp ; real c , 37 r e a l temp1 ; real q , 38 r e a l temp2 ; real d , 39 int start ; r e a l alpha , 40 i n t end ; r e a l gamma , 41 s t a r t =N∗( j −1)−( j ∗( j −1) ) /2 + 1 ; vector t , 42 end =j ∗N−( j ∗( j +1) ) / 2 ; v e c t o r m a g n i t u d e s43 y=t i m e s d i f f [ s t a r t : end ] ; , 44 z=exp(−q∗ l o g ( q u a d r a t i c f a c t o r A n i vector times diff [ s t a r t : end ] . / , 45 ( exp ( gamma∗( m a g n i t u d e s [ ( j +1) :] − vector latitudes , m a g n i t u d e 0 ) ) )+d ) ) ; v e c t o r l o n g i t u d e s46 y=( k∗ a l p h a ∗( p−1)∗c ˆ ( p−1)∗( q−1)∗d , ˆ ( q−1)∗(1/ p i ( ) ) ) vector 47 ∗exp ( ( a l p h a−gamma ) ∗( m a g n i t u d e s quadratic factorAni [ ( j +1) :] − , 48 magnitude0 ) ) vector 49 . ∗ exp(−p∗ l o g ( y+c ) ) ; q u a d r a t i c f 50 actorIso y=y . ∗ z ; , 51 s e i s m i c r a t e [ j ]=l o g (mu+sum ( y ) ) ; r e a l tmax , 52 temp=exp ( a l p h a ∗( m a g n i t u d e s [ j +1]− r e a l mag nitu de0 , magnitude0 ) ) ; real lat min , 53 temp1=exp ( gamma∗( m a g n i t u d e s [ j r e a l lat max , +1]−m a g n i t u d e 0 ) ) ; r e a l long min , 54 temp2=max ( q u a d r a t i c f a c t o r A n i [ r e a l long max , s t a r t : end ] ) ; real radius 55 i n t e g r a l o f r a t e [ j ]=k∗ a l p h a ∗temp ){ 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 ∗(1−c ˆ ( p−1)/ 82 ( ( t i m e s d i f f [ j ]+ c ) ˆ ( p−1) ) ) ∗(1−d83 ˆ ( q−1)/ 84 ( ( temp2 / ( temp1 )+d ) ˆ ( q−1) ) ) ; 85 } 86 i n t e g r a l m u=mu∗tmax∗ p i ( ) ∗ r a d i u s ˆ 2 87 ; l o g l i k e l i h o o d=sum ( s e i s m i c r a t e )−88 i n t e g r a l m u −sum ( i n t e g r a l o f r a t e89 ); 90 return ( l o g l i k e l i h o o d ) ; 91 92 } 93 } 94 data{ 95 i n t <l o w e r=0> N ; 96 v e c t o r [N] times ; 97 r e a l <l o w e r=0> m a x t i m e ; 98 v e c t o r [N] magnitudes ; 99 v e c t o r [ N∗(N−1) / 2 ] 100 quadratic factorAni ; 101 v e c t o r [ N∗(N−1) / 2 ] quadratic factorIso ; v e c t o r [ N∗(N−1) / 2 ] t i m e s d i f f ; 102 r e a l <l o w e r=0> t h r e s h o l d m a g n i t u d e ; v e c t o r [N] l a t i t u d e s ; 103 v e c t o r [N] l o n g i t u d e s ; real lat min ; 104 r e a l lat max ; r e a l long min ; 105 r e a l long max ; r e a l <l o w e r=0> r a d i u s ; 106 } parameters{ r e a l <l o w e r=0> mu ; r e a l <l o w e r=0> k ; r e a l <l o w e r=1.000005 > p ; r e a l <l o w e r=0> c ; r e a l <l o w e r=0> d ; r e a l <l o w e r=1.00005 > q ; r e a l <l o w e r=0> a l p h a ; r e a l <l o w e r=0> gamma ; } model{ mu˜ e x p o n e n t i a l ( 2 . 8 ) ; k˜ e x p o n e n t i a l ( 2 . 8 ) ; p˜ e x p o n e n t i a l ( 2 . 8 ) ; c˜ e x p o n e n t i a l ( 2 . 8 ) ; d˜ e x p o n e n t i a l ( 2 . 8 ) ; q˜ e x p o n e n t i a l ( 2 . 8 ) ; gamma˜ e x p o n e n t i a l ( 2 . 8 ) ; a l p h a−gamma˜ e x p o n e n t i a l ( 5 ) ; i n c r e m e n t l o g p r o b ( l o g l i k e l i h o o d (N, mu , k , p , c , q , d , a l p h a , gamma , t i m e s , m a g n i t u d e s , times diff , latitudes , longitudes , quadratic factorAni , q u a d r a t i c f a c t o r I s o , max time , threshold magnitude , l a t m i n , lat max , long min , long max , radius ) ) ; } Listing 4: Anisotropic spa23 24 tio temporal hypocentral Rstan 25 26 model with constant background 27 28 seismicity 29 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 30 functions{ 31 r e a l l o g l i k e l i h o o d ( i n t N, 32 r e a l mu , 33 real k , 34 real p , 35 real c , 36 real q , 37 real d , 38 r e a l alpha , 39 r e a l gamma , 40 r e a l eta , 41 vector t , 42 v e c t o r m a g n i t u d e s43 , 44 v e c t o r t i m e s d i f f45 , 46 vector 47 d e p t h s d i f f 48 , v e c t o r l a t i t u d e s 49 , v e c t o r l o n g i t u d e s50 , 51 vector depths , vector 52 quadratic factorAni , 53 vector 54 quadratic factorIso , 55 r e a l tmax , 56 r e a l mag nitu de0 , real real real real real real ){ lat min , lat max , long min , long max , radius , layer depth r e a l s e i s m i c r a t e [N ] ; r e a l i n t e g r a l o f r a t e [N ] ; real integral mu ; real log likelihood ; s e i s m i c r a t e [ N ]=l o g (mu) ; i n t e g r a l o f r a t e [ N ]=0 ; f o r ( j i n 1 : ( N−1) ) { v e c t o r [ N−j ] y ; v e c t o r [ N−j ] z ; v e c t o r [ N−j ] x ; v e c t o r [ N−j ] w ; r e a l temp ; r e a l temp1 ; r e a l temp2 ; r e a l temp3 ; int start ; i n t end ; s t a r t =N∗( j −1)−( j ∗( j −1) ) /2 + 1 ; end =j ∗N−( j ∗( j +1) ) / 2 ; y=t i m e s d i f f [ s t a r t : end ] ; z=exp(−q∗ l o g ( q u a d r a t i c f a c t o r A n i [ s t a r t : end ] . / ( exp ( gamma∗( m a g n i t u d e s [ ( j +1) :] − m a g n i t u d e 0 ) ) )+d ) ) ; y=( k∗ a l p h a ∗( p−1)∗c ˆ ( p−1)∗( q−1)∗d ˆ ( q−1)∗ ( 1 / p i ( ) ) ) ∗exp ( ( a l p h a−gamma ) ∗ ( m a g n i t u d e s [ ( j +1) :] − m a g n i t u d e 0 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 )) 82 . ∗ exp(−p∗ l o g ( y+c ) ) ; 83 x=y . ∗ z ; 84 z=( 1 / l a y e r d e p t h ) ∗ 85 86 d e p t h s d i f f [ s t a r t : end ] ; 87 y=( 1 / l a y e r d e p t h ) ∗ d e p t h s [ ( j +1) : N ] ; 88 f o r ( i i n 1 : ( N−j ) ) { 89 w [ i ]=( 1 / ( l a y e r d e p t h ∗ exp ( lbeta ( eta ∗ 90 ( y [ i ] ) + 1 , eta − eta ∗ ( y [ i ] )+ 1 ) ) ) ) ∗ 91 ( z [ i ] ˆ ( e t a ∗ ( y [ i ] ) ) ) ∗ 92 ((1 − z [ i ] ) ˆ 93 ( e t a−e t a ∗ ( y [ i ] ) ) ) ; 94 95 } s e i s m i c r a t e [ j ]=l o g (mu+sum ( x . ∗ 96 w) ) ; 97 temp=exp ( a l p h a ∗( m a g n i t u d e s [ j +1]− 98 magnitude0 ) ) ; 99 temp1=exp ( gamma∗( m a g n i t u d e s [ j 100 +1]−m a g n i t u d e 0 ) ) ; 101 temp2=max ( q u a d r a t i c f a c t o r A n i [ 102 s t a r t : end ] ) ; 103 i n t e g r a l o f r a t e [ j ]=k∗ a l p h a ∗temp 104 ∗(1−c ˆ ( p−1) 105 / ( ( t i m e s d i f f [ j ]+ c ) ˆ ( p−1) ) ) ∗(1− 106 d ˆ ( q−1) 107 / ( ( temp2 / ( temp1 )+d ) ˆ ( q−1) ) ) ; 108 } 109 i n t e g r a l m u=mu∗tmax∗ p i ( ) ∗ 110 layer depth∗ 111 ( r a d i u s ˆ2) ; 112 l o g l i k e l i h o o d=sum ( s e i s m i c r a t e )− 113 i n t e g r a l m u −sum ( i n t e g r a l o f r a t114 e ); 115 return ( l o g l i k e l i h o o d ) ; 116 } } data{ i n t <l o w e r=0> N ; v e c t o r [N] times ; r e a l <l o w e r=0> m a x t i m e ; v e c t o r [N] magnitudes ; v e c t o r [ N∗(N−1) / 2 ] quadratic factorAni ; v e c t o r [ N∗(N−1) / 2 ] quadratic factorIso ; v e c t o r [ N∗(N−1) / 2 ] t i m e s d i f f ; v e c t o r [ N∗(N−1) / 2 ] d e p t h s d i f f ; r e a l <l o w e r=0> t h r e s h o l d m a g n i t u d e ; v e c t o r [N] l a t i t u d e s ; v e c t o r [N] l o n g i t u d e s ; v e c t o r [N] depths ; real lat min ; r e a l lat max ; r e a l long min ; r e a l long max ; r e a l <l o w e r=0> r a d i u s ; r e a l <l o w e r=0> l a y e r d e p t h ; } parameters{ r e a l <l o w e r=0> mu ; r e a l <l o w e r=0> k ; r e a l <l o w e r=1.000005 > p ; r e a l <l o w e r=0> c ; r e a l <l o w e r=0> d ; r e a l <l o w e r=1.00005 > q ; r e a l <l o w e r=0> a l p h a ; r e a l <l o w e r=0> gamma ; r e a l <l o w e r=0> e t a ; } model{ mu˜ e x p o n e n t i a l ( 2 ) ; 117 118 119 120 121 122 123 124 125 k˜ e x p o n e n t i a l ( 2 ) ; 126 p˜ e x p o n e n t i a l ( 2 ) ; c˜ e x p o n e n t i a l (2) ; 127 d˜ e x p o n e n t i a l ( 2 ) ; 128 q˜ e x p o n e n t i a l ( 2 ) ; 129 eta ˜ exponential (2) ; 130 gamma˜ e x p o n e n t i a l ( 2 ) ; a l p h a−gamma˜ e x p o n e n t i a l ( 5 ) ; 131 i n c r e m e n t l o g p r o b ( l o g l i k e l i h o o d (N,132 mu , k , p , c , q , d , a l p h a , gamma , e t a , t i m e s , m a g n i t u d e s , times diff , depths diff , latitudes , longitudes , depths , q u a d r a t i c f a c t o r A n i , q u a d r a t i c f a c t o r I s o , max time , threshold magnitude , lat min , lat max , long min , lo n g m a x , r a d i u s , l a y e r d e p t h ) ) ; } Listing 5: Anisotropic Rstan 27 28 model with variable background 29 30 seismicity 31 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 32 functions{ 33 r e a l l o g l i k e l i h o o d ( i n t N, 34 r e a l mu , 35 real k , 36 real p , 37 real c , 38 real q , 39 real d , 40 r e a l alpha , 41 r e a l gamma , 42 vector t , 43 v ec t or magnitudes , 44 vector times diff , 45 vector latitudes , 46 vector longitudes , vector 47 background seismic , 48 vector q u a d r a t i c f a c t o r A49n i , vector 50 quadratic factorIso , 51 r e a l tmax , 52 r e a l mag nitu de0 , 53 real lat min , r e a l lat max , r e a l long min , 54 r e a l long max , real radius 55 ){ r e a l s e i s m i c r a t e [N ] ; r e a l i n t e g r a l o f r a t e [N ] ; real integral mu ; real log likelihood ; s e i s m i c r a t e [ N ]=l o g (mu) ; i n t e g r a l o f r a t e [ N ]=0 ; f o r ( j i n 1 : ( N−1) ) { v e c t o r [ N−j ] y ; v e c t o r [ N−j ] z ; v e c t o r [ N−1] x ; r e a l temp ; r e a l temp1 ; r e a l temp2 ; int start ; i n t end ; s t a r t =N∗( j −1)−( j ∗( j −1) ) /2 + 1 ; end =j ∗N−( j ∗( j +1) ) / 2 ; y=t i m e s d i f f [ s t a r t : end ] ; z= exp(−q∗ l o g ( q u a d r a t i c f a c t o r A n i [ s t a r t : end ] . / ( exp ( gamma∗( m a g n i t u d e s [ ( j +1) rates :] − m a g n i t u d e 0 ) ) )+d ) ; y=( k∗ a l p h a ∗( p−1)∗c ˆ ( p−1)∗( q−1)∗d ˆ ( q−1)∗ ( 1 / p i ( ) ) ) ∗exp ( ( a l p h a−gamma ) ∗( m a g n i t u d e s [ ( j +1) : ] −m a g n i t u d e 0 ) ) . ∗ exp(−p∗ l o g ( y+c ) ); y=y . ∗ z ; s e i s m i c r a t e [ j ]= l o g (mu∗ background seismic rates [ j +1]+sum ( y ) ) ; temp=exp ( a l p h a ∗( m a g n i t u d e s [ j +1]− magnitude0 ) ) ; temp1=exp ( gamma∗( m a g n i t u d e s [ j 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 +1]−m a g n i t u d e 0 ) ) ; 83 temp2=max ( q u a d r a t i c f a c t o r A n i [ 84 85 s t a r t : end ] ) ; i n t e g r a l o f r a t e [ j ]=k∗ a l p h a ∗temp86 87 ∗(1−c ˆ ( p−1)/ 88 ( ( t i m e s d i f f [ j ]+ c ) ˆ ( p−1) ) ) ∗ (1−d ˆ ( q−1) / ( ( temp2 / ( temp1 )+d ) ˆ (89 90 q−1) ) ) ; 91 } 92 i n t e g r a l m u=mu∗sum ( b a c k g r o u n d s e i s m i c r a t e s ) ∗ 93 94 tmax∗ p i ( ) ∗ r a d i u s ˆ 2 ; l o g l i k e l i h o o d=sum ( s e i s m i c r a t e )−95 i n t e g r a l m u −sum ( i n t e g r a l o f r a t e96 97 ); return ( l o g l i k e l i h o o d ) ; 98 99 } 100 } 101 data{ 102 i n t <l o w e r=0> N ; 103 v e c t o r [N] times ; 104 r e a l <l o w e r=0> m a x t i m e ; v e c t o r [N] magnitudes ; 105 v e c t o r [ N∗(N−1) / 2 ] quadratic factorAni ; 106 v e c t o r [ N∗(N−1) / 2 ] quadratic factorIso ; 107 v e c t o r [ N∗(N−1) / 2 ] t i m e s d i f f ; r e a l <l o w e r=0> t h r e s h o l d m a g n i t u d e ; 108 v e c t o r [N] l a t i t u d e s ; v e c t o r [N] l o n g i t u d e s ; 109 v e c t o r [ N ] b a c k g r o u n d s e i s m i c r a t e s ;110 real lat min ; r e a l lat max ; 111 r e a l long min ; r e a l long max ; r e a l <l o w e r=0> r a d i u s ; } parameters{ r e a l <l o w e r=0> mu ; r e a l <l o w e r=0> k ; r e a l <l o w e r=1.000005 > p ; r e a l <l o w e r=0> c ; r e a l <l o w e r=0> d ; r e a l <l o w e r=1.00005 > q ; r e a l <l o w e r=0> a l p h a ; r e a l <l o w e r=0> gamma ; } model{ mu˜ e x p o n e n t i a l ( 2 . 8 ) ; k˜ e x p o n e n t i a l ( 2 . 8 ) ; p˜ e x p o n e n t i a l ( 2 . 8 ) ; c˜ e x p o n e n t i a l ( 2 . 8 ) ; d˜ e x p o n e n t i a l ( 2 . 8 ) ; q˜ e x p o n e n t i a l ( 2 . 8 ) ; gamma˜ e x p o n e n t i a l ( 2 . 8 ) ; a l p h a − gamma ˜ e x p o n e n t i a l ( 5 ) ; i n c r e m e n t l o g p r o b ( l o g l i k e l i h o o d (N, mu , k , p , c , q , d , a l p h a , gamma , t i m e s , m a g n i t u d e s , times diff , latitudes , longitudes , background seismic rates , quadratic factorAni , quadratic factorIso , max time , t h r e s h o l d m a g n i t u d e , l a t m i n , lat max , long min , long max , radius ) ) ; } Methods We can estimate the probability that a given event is spontaneous or is triggered by others Kagan1980Zhuang2002. The contribution of the spontaneous seismicity rate to the occurrence of an event i can be taken as the probability that the event i is spontaneousZhuang2008: µ(xi ,yi ) φ(i) = λ(t i ,xi ,yi ) Similarly, the probability that the event j is produced by the event κ(M)g (tj −ti )f (xj −xi ,yj −yi ,mi ) i is ρij = λ(ti ,xi ,yi ) We can also obtain the expected number of direct aftershocks P from the earthquake i as j ρij Zhuang2008 Methods Inter-event times The probability density function of the recurrence times (time between two successive events) τ H(τ ) ≈ λf (λτ ) where the function f (x) has been found practically the same in different regions and λ is the average rate of events observed in the analyzed region. Saichev2007 The scaling factor of times between earthquakes is taken as the inverse of its mean. The form of the function f (x) which is demonstrated in Saichev2007 is f (x) = (nθ x −1−θ + [1 − n + nθ x −θ ]2 ) ∗ ϕ(x, ) Results Anisotropic Distribution The covariance matrix for the cluster associated with the April 16th big earthquake (804 earthquakes in the cluster) is 1.469 −0.696 −0.696 0.709 and corresponds to the fourth bivariate model fitted. Results Kernel bivariate density Kernel bivariate density using the R package kde. Priors Weakly informative priors For the ETAS parameters(must be positive) we used exponential priors and for p and q we use a minimum value close to 1:1.000005. The radius of the minimum covering circle using Welzl algorithm was, r = 1.70479. Results Figure: Chains for anisotropic ETAS model with constant background seismicity Figure: A posteriori parameter distributions for anisotropic ETAS model with constant background seismicity Results Figure: Correlation of parameter values in the chains for anisotropic ETAS model with constant background seismicity Figure: Correlation of parameter values in the chains for anisotropic ETAS model with constant background seismicity Results Residuals Figure: Acumulated number of events for temporal Etas model with constant background seismicity Figure: Residuals for Etas temporal temporal Etas model with constant background seismicity Figure: Accumulated number of events for temporal ETAS model with variable background seismicity Figure: Residuals for temporal ETAS model with variable background seismicity Figure: Accumulated number of events for temporal ETAS model with constant background seismicity vs variable background seismicity Figure: Residuals for temporal ETAS model with constant background seismicity vs variable background seismicity Figure: Accumulated number of events for temporal ETAS with magnitudes model and constant background seismicity Figure: Residuals for temporal ETAS with magnitudes model and constant background seismicity Figure: Accumulated number of events for spatio temporal anisotropic ETAS model and variable background seismicity Figure: Residuals for spatio temporal anisotropic ETAS model and variable background seismicity Results Parent earthquakes 95% credibility intervals for the index of the most probable parent earthquake with 1000 draws from the posterior distributions. The green line is the big earthquake on April 16 and blue points are the medians of the credibility intervals using the anisotropic spatio temporal model with variable background seismicity. Thanks