# Fitting procedure of the latent variable model

### Description

Metropolis-within-Gibbs algorithm that returns posterior distribution (as Markov chains) for the marginal GEV parameters of an observed spatial process.
This function is close to `hkevp.fit`

but with less parameters since conditional independence is assumed and only the margins are estimated.
In `SpatialExtremes`

library, a similar function can be found under the name `latent`

.

### Usage

1 2 | ```
latent.fit(y, sites, niter, nburn, nthin, quiet, trace, gev.vary,
spatial.covariates, log.scale, correlation, mcmc.init, mcmc.prior, mcmc.jumps)
``` |

### Arguments

`y` |
A matrix of observed block maxima. Each column corresponds to a site position. |

`sites` |
The coordinates of the sites where the data are observed. Each row corresponds to a site position. |

`niter` |
The number of MCMC iterations. |

`nburn` |
The number of first MCMC iterations that are discarded. Zero by default. |

`nthin` |
The size of the MCMC thinning. One by default (i.e. no thinning). |

`quiet` |
A logical indicating if the progression of the routine should be displayed. TRUE by default. |

`trace` |
If |

`gev.vary` |
A logical vector of size three indicating if the GEV parameters (respectively the location, the scale and the shape) are spatially-varying. If not (by default for the shape), the parameter is the same at each position. |

`spatial.covariates` |
A numerical matrix of spatial covariates. Each row corresponds to a site position. See details. |

`log.scale` |
A logical value indicating if the GEV scale parameter |

`correlation` |
A character string indicating the form of the correlation function associated to the latent Gaussian processes that describes the marginal parameters. Must be one of |

`mcmc.init` |
A named list indicating the initial states of the chains. See details. |

`mcmc.prior` |
A named list indicating the hyperparameters of the prior distributions. See details. |

`mcmc.jumps` |
A named list indicating the amplitude of the jumps to propose the MCMC candidates. See details. |

### Details

Details of the MCMC procedure are presented in Davison et al. (2012). This function follows the indications and the choices of the authors, with the exception of several small changes:

The scale parameter

*σ*can be modelled like the two other marginal parameters as in Davison et al. (2012) or by its logarithm as in Reich and Shaby (2012). For this, use the argument`log.scale`

, set to FALSE by default.The Inverse-Gamma prior distributions defined for the bandwith parameter

*τ*and for the ranges*λ*of the latent processes are replaced by a Beta distribution over the interval*[0,2D_{max}]*, where*D_{max}*stands for the maximum distance between two sites.

If the the parameters are assumed spatially-varying, the user can provide spatial covariates to fit the mean of the latent Gaussian processes. Recall for instance for the GEV location parameter that:

*μ(s) = β_{0,μ} + β_{1,μ} c_1(s) + ... + β_{p,μ} c_p(s) ~.*

The given matrix `spatial.covariates`

that represents the *c_i(s)* elements should have the first column filled with ones to account for the intercept *β_0*.

The arguments `mcmc.init`

, `mcmc.prior`

and `mcmc.jumps`

are named list that have default values. The user can make point changes in these arguments, by setting `mcmc.init = list(loc = .5)`

for instance, but must respect the constraints of each element:

`mcmc.init`

: all elements are of length one. The possible elements are:`loc`

,`scale`

and`shape`

(GEV parameters).`range`

and`sill`

of the correlation functions.

mcmc.prior: the possible elements are:

`constant.gev`

: a*2 \times 3*matrix of normal parameters for spatially-constant*μ*,*σ*and*ξ*. The first row are the means, the second are the standard deviations.`beta.sd`

: the normal sd prior of all*β*parameters (a single value).`range`

: the two Beta parameters.`sill`

: the two Inverse-Gamma parameters.

mcmc.jumps: the possible elements are

`gev`

and`range`

, vectors of length 3 (for each GEV parameter).

### Value

A named list with following elements (less elements if `fit.margins`

is `FALSE`

):

`GEV`

: the Markov chains associated to the GEV parameters. The dimensions of the array correspond respectively to the sites positions, the three GEV parameters and the states of the Markov chains.`llik`

: the log-likelihood of the model for each step of the algorithm.`time`

: time (in sec) spent for the fit.`spatial`

: a named list with four elements linked to the GEV spatially-varying parameters:`vary`

: the argument`gev.vary`

.`beta`

: the*β*parameters for each GEV parameter. The dimensions correspond respectively to the steps of the Markov chains, the*p*spatial covariates and the GEV parameters`sills`

: the Markov chains associated to the sills in the correlation functions of the latent Gaussian processes.`ranges`

: the Markov chains associated to the ranges in the correlation functions of the latent Gaussian processes.

`data`

: the data fitted.`sites`

: the sites where the data are observed.`spatial.covariates`

: the spatial covariates.`correlation`

: the type of correlation function for the marginal latent processes.`nstep`

: the number of steps at the end of the routine after burn-in and thinning.`log.scale`

: a boolean indicating if the scale parameter has been modelled via its logarithm.`fit.type`

: "latent" character string to specify the type of fit.

### Author(s)

Quentin Sebille

### References

Reich, B. J., & Shaby, B. A. (2012). A hierarchical max-stable spatial model for extreme precipitation. The annals of applied statistics, 6(4), 1430. <DOI:10.1214/12-AOAS591>

Davison, A. C., Padoan, S. A., & Ribatet, M. (2012). Statistical modeling of spatial extremes. Statistical Science, 27(2), 161-186. <DOI:10.1214/11-STS376>

### See Also

hkevp.fit

### Examples

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | ```
# Simulation of HKEVP:
sites <- as.matrix(expand.grid(1:4,1:4))
loc <- sites[,1]*10
scale <- 3
shape <- .2
alpha <- 1
tau <- 2
ysim <- hkevp.rand(15, sites, sites, loc, scale, shape, alpha, tau)
# Latent Variable Model fit:
set.seed(1)
fit <- latent.fit(ysim, sites, niter = 10000, nburn = 5000, nthin = 5)
mcmc.plot(fit, TRUE)
par(mfrow = c(2,2))
apply(fit$GEV[,1,], 1, acf)
``` |