# dep2fit: Dependence model fit (stepwise) In tsxtreme: Bayesian Modelling of Extremal Dependence in Time Series

## Description

The conditional Heffernan–Tawn model is used to fit the dependence in time of a stationary series. A standard 2-stage procedure is used.

## Usage

 ```1 2 3``` ```dep2fit(ts, u.mar = 0, u.dep, lapl = FALSE, method.mar = c("mle","mom","pwm"), nlag = 1, conditions = TRUE) ```

## Arguments

 `ts` numeric vector; time series to be fitted. `u.mar` marginal threshold; used when transforming the time series to Laplace scale. `u.dep` dependence threshold; level above which the dependence is modelled. `u.dep` can be lower than `u.mar`. `lapl` logical; is `ts` on the Laplace scale already? The default (FALSE) assumes unknown marginal distribution. `method.mar` a character string defining the method used to estimate the marginal GPD; either `"mle"` for maximum likelihood of `"mom"` for method of moments. Defaults to `"mle"`. `nlag` integer; number of lags to be considered when modelling the dependence in time. `conditions` logical; should conditions on α and β be set? (see Details) Defaults to `TRUE`.

## Details

Consider a stationary time series (X_t) with Laplace marginal distribution; the fitting procedure consists of fitting

X_t = α_t * x_0 + x_0^{β_t} * Z_t, t=1,…,m,

with m the number of lags considered. A likelihood is maximised assuming Z_t ~ N(μ_t, σ^2_t), then an empirical distribution for the Z_t is derived using the estimates of α_t and β_t and the relation

Z_t = (X_t - α_t * x_0) / x_0^{β_t}.

`conditions` implements additional conditions suggested by Keef, Papastathopoulos and Tawn (2013) on the ordering of conditional quantiles. These conditions help with getting a consistent fit by shrinking the domain in which (α,β) live.

## Value

 `alpha ` parameter controlling the conditional extremal expectation. `beta ` parameter controlling the conditional extremal expectation and variance. `res ` empirical residual of the model. `pars.se ` vector of length 2 giving the estimated standard errors for `alpha` and `beta` given by the hessian matrix of the likelihood function used in the first step of the inference procedure.

`depfit`, `theta2fit`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23``` ```## 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) plot(ar, type="l") plot(density(ar)) grid <- seq(-3,3,0.01) lines(grid, dnorm(grid), col="blue") ## rescale margin ar <- qlapl(pnorm(ar)) ## fit model without constraints... fit1 <- dep2fit(ts=ar, u.mar = 0.95, u.dep=0.98, conditions=FALSE) fit1\$a; fit1\$b ## ...and compare with a fit with constraints fit2 <- dep2fit(ts=ar, u.mar = 0.95, u.dep=0.98, conditions=TRUE) fit2\$a; fit2\$b# should be similar, as true parameters lie well within the constraints ```