Last data update: 2014.03.03

R: Calculation of moving average for a vector
ma.vectorR Documentation

Calculation of moving average for a vector

Description

This functions calculates the moving average for a vector.

Usage

ma.vector(A,M,av="median",delta=50)

Arguments

A

vector of predictor to be used for sorting

M

vector of variable to be averaged

av

averaging by mean or median (default)

delta

even integer determining the size of the sliding window (2*delta+1.)

Details

The function ma.vector first sorts M according to the corresponding values of A. Subsequently, a moving average is calculated with window size (2*delta+1). The values for the moving average are set to zero if the corresponding window extends over the boarder of the vector M.

Value

Vector with moving average values of M

Author(s)

Matthias E. Futschik,http://itb.biologie.hu-berlin.de/~futschik

See Also

ma.matrix

Examples

### LOADING DATA
data(sw)
A <- maA(sw[,1])
M <- maM(sw[,1])
  
# MA-PLOT 
plot(A,M)

# MOVING AVERAGE
Mav <- ma.vector(A,M,av="median",delta=100)
points(A,Mav,col="red")

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(OLIN)
Loading required package: locfit
locfit 1.5-9.1 	 2013-03-22
Loading required package: marray
Loading required package: limma
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/OLIN/ma.vector.Rd_%03d_medium.png", width=480, height=480)
> ### Name: ma.vector
> ### Title: Calculation of moving average for a vector
> ### Aliases: ma.vector
> ### Keywords: utilities regression
> 
> ### ** Examples
> 
> ### LOADING DATA
> data(sw)
> A <- maA(sw[,1])
> M <- maM(sw[,1])
>   
> # MA-PLOT 
> plot(A,M)
> 
> # MOVING AVERAGE
> Mav <- ma.vector(A,M,av="median",delta=100)
> points(A,Mav,col="red")
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>