% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/replace_helpers.R
\name{compute_local_windows}
\alias{compute_local_windows}
\alias{compute_local_fun}
\alias{compute_outliers}
\alias{compute_valid_neighbours}
\title{Computes rolling local values}
\usage{
compute_local_windows(
  t,
  idx = seq_along(t),
  width = NULL,
  span = NULL,
  align = c("centre", "left", "right")
)

compute_local_fun(x, window_idx, fn, ...)

compute_outliers(x, window_idx, outlier_cutoff)

compute_valid_neighbours(
  x,
  t = seq_along(x),
  width = NULL,
  span = NULL,
  verbose = TRUE
)
}
\arguments{
\item{t}{An \emph{optional} numeric vector of the predictor variable (e.g. time).
Default is \code{seq_along(x)}.}

\item{idx}{A numeric vector of indices of \code{t} at which to calculate local
windows. All indices of \code{t} by \emph{default}, or can be used to only calculate
for known indices, such as invalid values of \code{x}.}

\item{width}{An integer defining the local window in number of samples
around \code{idx} in which to perform the operation, according to \code{align}.}

\item{span}{A numeric value defining the local window time span around \code{idx}
in which to perform the operation, according to \code{align}. In units of
\code{time_channel} or \code{t}.}

\item{align}{Window alignment as \emph{"centre"/"center"} (the \emph{default}),
\emph{"left"}, or \emph{"right"}. Where \emph{"left"} is \emph{forward looking}, and \emph{"right"}
is \emph{backward looking} from the current sample.}

\item{x}{A numeric vector of the response variable.}

\item{window_idx}{A list the same or shorter length as \code{x} with numeric
vectors for the sample indices of local rolling windows.}

\item{fn}{A function to pass through for local rolling calculation.}

\item{...}{Additional arguments.}

\item{outlier_cutoff}{A numeric value for the local outlier threshold, as
the number of standard deviations from the local median.
\itemize{
\item Default \code{NULL} will not replace outliers.
\item Lower values are more sensitive and flag more outliers; higher values
are more conservative.
\item \code{outlier_cutoff = 3} Pearson's 3 sigma edit rule.
\code{outlier_cutoff = 2} approximates a Tukey-style 1.5*IQR rule.
\code{outlier_cutoff = 0} Tukey's median filter.
}}

\item{verbose}{Logical. Default is \code{TRUE}. Display or silence (if \code{FALSE})
warnings and information messages helpful for troubleshooting. Ad
global default can be set via \code{options(mnirs.verbose = FALSE)}.}
}
\value{
\code{compute_local_windows()}: A list the same length as \code{idx} and the same or
shorter length as \code{t} with numeric vectors of sample indices of length
\code{width} samples or \code{span} units of time \code{t}.

\code{compute_local_fun()}: A numeric vector the same length as \code{x}.

\code{compute_outliers()}: A \code{list()} with vectors the same length as \code{x} for
with numeric local medians and logical identifying where \code{is_outlier}.

\code{compute_valid_neighbours()}: A list the same length as the \code{NA} values in
\code{x} with numeric vectors of sample indices of length \code{width} samples or
\code{span} units of time \code{t} for valid values neighbouring split to either
side of the invalid \code{NA}s.
}
\description{
\code{compute_local_windows()}: Compute a list of rolling window indices along a
time variable \code{t}.

\code{compute_local_fun()}: Compute a rolling function along \code{x} from a list of
rolling sample windows.

\code{compute_outliers()}: Computes a vector of local medians and logicals
indicating outliers of \code{x} within a list of rolling sample windows
\code{window_idx}.

\code{compute_valid_neighbours()}: Compute a list of rolling window indices along
\code{x} to either side of \code{NA}s.
}
\details{
The local rolling window can be specified by either \code{width} as the number of
samples, or \code{span} as the time span in units of \code{t}. Specifying \code{width}
is often faster than \code{span}.

\code{align} defaults to \emph{"centre"} the local window around \code{idx} between
\verb{[idx - floor((width-1)/2),} \verb{idx + floor(width/2)]} when \code{width} is
specified. Even \code{width} values will bias \code{align} to \emph{"left"}, with the
unequal sample forward of \code{idx}, effectively returning \code{NA} at the last
sample index. When \code{span} is specified, the local window is between
\verb{[t - span/2, t + span/2]}.
}
\keyword{internal}
