Using a sliding square window this function produces
the moving average for a matrix.
Usage
ma.matrix(X,av="median",delta= 2,edgeNA=FALSE )
Arguments
X
matrix
av
averaging by mean or median (default)
delta
integer determining the size of the sliding square window
(2*delta+1)x(2*delta+1).
edgeNA
treatment of edges of array: For edgeNA=TRUE,
averaged values of sliding windows are set to NA
if the corresponding
windows extend over the edges of the matrix.
Details
A square window with size (2*delta+1)x(2*delta+1) is moved over the entire
matrix and a new matrix is created with each value equals the average value in the corresponding
window. This procedure defines a local regression of zeroth order.
### LOADING DATA
data(sw)
### GENERATION OF MATRIX
Morig <- v2m(maM(sw)[,1],Ngc=maNgc(sw),Ngr=maNgr(sw),Nsc=maNsc(sw),Nsr=maNsr(sw),visu=TRUE)
### AVERAGING BY MA.MATRIX
Mav <- ma.matrix(Morig,av="median",delta= 2,edgeNA=FALSE )
### VISUALISATION
m2v(Mav,Ngc=maNgc(sw),Ngr=maNgr(sw),Nsc=maNsc(sw),Nsr=maNsr(sw),visu=TRUE)
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.matrix.Rd_%03d_medium.png", width=480, height=480)
> ### Name: ma.matrix
> ### Title: Calculation of moving average for a matrix
> ### Aliases: ma.matrix
> ### Keywords: utilities regression
>
> ### ** Examples
>
>
> ### LOADING DATA
> data(sw)
>
> ### GENERATION OF MATRIX
> Morig <- v2m(maM(sw)[,1],Ngc=maNgc(sw),Ngr=maNgr(sw),Nsc=maNsc(sw),Nsr=maNsr(sw),visu=TRUE)
>
> ### AVERAGING BY MA.MATRIX
> Mav <- ma.matrix(Morig,av="median",delta= 2,edgeNA=FALSE )
>
> ### VISUALISATION
> m2v(Mav,Ngc=maNgc(sw),Ngr=maNgr(sw),Nsc=maNsc(sw),Nsr=maNsr(sw),visu=TRUE)
>
>
>
>
>
>
> dev.off()
null device
1
>