runmean: Compute a running mean of a vector

View source: R/runmean.R

runmeanR Documentation

Compute a running mean of a vector

Description

This function essentially uses the running.mean function from the igraph package. However, adjustments are made to ensure that the output is always the same length as the input (by fiddling at the boundaries).

Usage

runmean(x, binwidth)

Arguments

x

Vector that you wish to smooth using a running mean.

binwidth

Number of ordinates over which you wish to average

Details

For example, if binwidth=2 and x=1:6 then the function averages each pair to get 1.5, 2.5, 3.5, 4.5, 5.5. However, this is only 5 numbers and the input had 6. So, in this case the function arranges for the output to be extended (in this case 1 gets padded onto the front. For vectors of length > 3 the padding depends on whether the vector is even or odd.

Value

The running mean of the input at the given bandwidth.

Author(s)

Guy Nason.

References

Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1111/rssb.12015")}

See Also

ewspec3

Examples

runmean(1:6, 2)
#
# [1] 1.0 1.5 2.5 3.5 4.5 5.5
#
runmean(1:14, 4)
#
#  [1]  1.75  2.50  3.50  4.50  5.50  6.50  7.50  8.50  9.50 10.50 11.50 12.5
# [13] 13.25 13.50
#

locits documentation built on Sept. 8, 2023, 5:07 p.m.