Learn R Programming

locits (version 1.7.7)

runmean: 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)

Value

The running mean of the input at the given bandwidth.

Arguments

x

Vector that you wish to smooth using a running mean.

binwidth

Number of ordinates over which you wish to average

Author

Guy Nason.

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.

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. tools:::Rd_expr_doi("10.1111/rssb.12015")

See Also

ewspec3

Examples

Run this code
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
#

Run the code above in your browser using DataLab