# corGaussian: Correlation functions In OakleyJ/MUCM: Gaussian process emulator methods based on the MUCM toolkit

## Description

Functions to calculate the correlation between two points. The correlation functions give the correlation between the simulator output at any given vector of input values and the output at any other given input vector. Within this package, when these two vectors are the same then the correlation function `C` at input vector `x` is `C(x,x) = 1` In principal, the correlation function can take a very wide variety of forms. Only a few are included in this package, however, a user is able to define his own function. A user defined function must follow the same signature as those included in this package.

## Usage

 ```1 2 3 4 5 6 7 8 9``` ```corGaussian(inputs, inputs2, phi) corMatern2.5(inputs, inputs2, phi) corGaussianPeriodic(inputs, inputs2, phi, period) corGaussianPeriodic2(inputs, inputs2, phi, period) corCombined(inputs, inputs2, phi, cor.funcs, ...) ```

## Arguments

 `inputs` A data frame, matrix or vector containing the input values of the data where each row gives the observations. `inputs2` An additional data frame, matrix or vector containing the input values of the data where each row gives the observations. `phi` Estimate of the roughness parameter (a vector). `period` A scalar or a vector indicating the period for each input parameter. If scalar, period for all input parameters will be set to the same scalar value as specified. Set period such that cor(x_i, x_i + period) = 1 `cor.funcs` An ordered vector of length equal to number of inputs containing characters `'g'`, `'m2.5'`, `'gp'`, or `'gp2'` as an indicator for whether a particular input should be calculated using `corGaussian`, `corMatern2.5`, `corGaussianPeriodic`, or `corGaussianPeriodic2` respectively. `...` Additional arguments to be passed on to correlation functions.

## Details

`corGaussian` uses the Gaussian correlation function defined as

∏ _{i=1}^{n} exp(-((x_i - x_i') / δ_i)^2)

`corMatern2.5` uses the Matern correlation function with ν = 2.5 defined as

(1 + (5^0.5)*r + (5*r^2)/3) * exp(-(5^0.5)*r)

where r is distance between inputs x_i and x_j, scaled by delta:

[(x_{i1}-x_{j1})^2 / δ_1^2 +...+ (x_{id}-x_{jd})^2 / δ_d^2 ]^{0.5}

`corGaussianPeriodic` uses the Gaussian periodic correlation function defined as

exp( - δ ^2 * sin (π/period * |(x_i - x_j)|)^2)

`corGaussianPeriodic2` uses a different way of accounting for the periodicity in the data. Both `corGaussianPeriodic` and `corGaussianPeriodic2` give the same results.

`corCombined` is a function that allows the user to specify a different correlation function for each output (from the list of predefined functions).

## Value

Returns the correlation matrix A calculated by the specific function.

## Note

These functions use `rdist` from package fields for speed.

## Author(s)

Sajni Malde and Jeremy Oakley

See `optim` or `MCMCMetropolisGibbs` where the function is used.