# empfit: Runs estimator In tsxtreme: Bayesian Modelling of Extremal Dependence in Time Series

## Description

Compute the empirical estimator of the extremal index using the runs method (Smith & Weissman, 1994, JRSSB).

## Usage

 ```1 2 3 4``` ```thetaruns(ts, lapl = FALSE, nlag = 1, u.mar = 0, probs = seq(u.mar, 0.995, length.out = 30), method.mar = c("mle", "mom", "pwm"), R.boot = 0, block.length = (nlag+1) * 5, levels = c(0.025, 0.975)) ```

## Arguments

 `ts` a vector, the time series for which to estimate the threshold-based extremal index θ(x,m), with x a probability level and m a run-length (see details). `lapl` logical; is `ts` on the Laplace scale already? The default (FALSE) assumes unknown marginal distribution. `nlag` the run-length; an integer larger or equal to 1. `u.mar` marginal threshold (probability); used when transforming the time series to Laplace scale if `lapl` is FALSE; if `lapl` is TRUE, it is nevertheless used when bootstrapping, since the bootstrapped series generally do not have Laplace marginal distributions. `probs` vector of probabilities; the values of x for which to evaluate θ(x,m). `method.mar` a character string defining the method used to estimate the marginal GPD; either `"mle"` for maximum likelihood or `"mom"` for method of moments or `"pwm"` for probability weighted moments methods. Defaults to `"mle"`. `block.length` integer; the block length used for the block-bootstrapped confidence intervals. `R.boot` integer; the number of samples used for the block bootstrap. `levels` vector of probabilites; the quantiles of the posterior distribution of the extremal index θ(x,m) to output.

## Details

Consider a stationary time series (X_t). A characterisation of the extremal index is

θ(x,m) = Pr(X_1≤ x,…,X_m≤ x | X_0≥ x).

In the limit when x and m tend to appropriately, θ corresponds to the asymptotic inverse mean cluster size. It also links the generalised extreme value distribution of the independent series (Y_t), with the same marginal distribution as (X_t),

G_Y(z)=G_X^θ(z),

with G_X and G_Y the extreme value distributions of (X_t) and (Y_t) respectively.

`nlag` corresponds to the run-length m and `probs` is a set of values for x. The runs estimator is computed, which consists of counting the proportion of clusters to the number of exceedances of a threshold x; two exceedances of the threshold belong to different clusters if there are at least m+1 non-exceedances inbetween.

## Value

An object of class '`depmeasure`' containing:

 `theta ` matrix; estimates of the extremal index θ(x,m) with rows corresponding to the `probs` values of x and the columns to the runs estimate and the chosen `levels`-quantiles of the bootstrap distribution. `nbr.exc ` numeric vector; number of exceedances for each threshold corresponding to the elements in `probs`. `probs ` `probs`. `levels ` numeric vector; `probs` converted to the original scale of `ts`. `nlag ` `nlag`.

`theta2fit`, `thetafit`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15``` ```## generate data from an AR(1) ## with Gaussian marginal distribution n <- 10000 dep <- 0.5 ar <- numeric(n) ar[1] <- rnorm(1) for(i in 2:n) ar[i] <- rnorm(1, mean=dep*ar[i-1], sd=1-dep^2) ## transform to Laplace scale ar <- qlapl(pnorm(ar)) ## compute empirical estimate theta <- thetaruns(ts=ar, u.mar=.95, probs=c(.95,.98,.99)) ## output plot(theta, ylim=c(.2,1)) abline(h=1, lty="dotted") ```