# R/msd2acf.R In SuperGauss: Superfast Likelihood Inference for Stationary Gaussian Time Series

#### Documented in msd2acf

#' @title Convert mean square displacement to autocorrelations.
#'
#' @description Converts the mean squared displacement (MSD) of positions to the autocorrelation (ACF) of the corresponding increments.
#' @param msd Length-\code{N} vector of MSDs at regular timepoints \code{ dt, 2*dt, ..., N*dt}.
#' @return Length \code{N} vector of ACFs.
#' @details
#' For a stationary increments process \eqn{X_t}, converts a sequence \eqn{\eta_1, \ldots, \eta_N} of regularly spaced MSDs,
#' \deqn{
#' \eta_i = E[(X_{i\Delta t} - X_0)^2],
#' }{
#' \eta_i = E[(X_(i*\Delta t) - X_0)^2],
#' }
#' into \eqn{\gamma_1, \ldots, \gamma_N}, a sequence of regularly spaced ACFs,
#' \deqn{
#' \gamma_i = \mathrm{cov}\{X_{(i+1)\Delta t} - X_{i \Delta_i}, X_{\Delta t} - X_{0}\}.
#' }{
#' \gamma_i = cov{X_((i+1)*\Delta t) - X_(i * \Delta t), X_(\Delta t) - X_0}.
#' }
#' This only produces correct results when \code{msd} corresponds to equally-spaced observations.
#' @examples
#' # autocorrelation of fBM increments
#' msd2acf(msd = fbm.msd(tseq = 0:10, H = .3))
#' @export
msd2acf <- function(msd) {
n <- length(msd)
gam <- rep(NA, n)
Gam <- diff(c(0, msd))
gam[-1] <- .5 * diff(Gam)
gam <- msd
gam
}


## Try the SuperGauss package in your browser

Any scripts or data that you put into this service are public.

SuperGauss documentation built on May 1, 2019, 7:58 p.m.