Description Usage Arguments Details Value Author(s) See Also Examples
Missing value replacement by weighted moving average. Uses semiadaptive window size to ensure all NAs are replaced.
1  na.ma(x, k = 4, weighting = "exponential")

x 
Numeric Vector ( 
k 
integer width of the moving average window. Expands to both sides of the center element e.g. k=2 means 4 observations (2 left, 2 right) are taken into account. If all observations in the current window are NA, the window size is automatically increased until there are at least 2 nonNA values present. 
weighting 
Weighting to be used. Accepts the following input:

In this function missing values get replaced by moving average values. Moving Averages are also sometimes referred to as "moving mean", "rolling mean", "rolling average" or "running average".
The mean in this implementation taken from an equal number of observations on either side of a central value.
This means for an NA value at position i
of a time series, the observations i1,i+1 and i+1, i+2 (assuming a window size of k=2)
are used to calculate the mean.
Since it can in case of long NA gaps also occur, that all values next to the central value are also NA, the algorithm has a semiadaptive window size. Whenever there are less than 2 nonNA values in the complete window available, the window size is incrementally increased, till at least 2 nonNA values are there. In all other cases the algorithm sticks preset window size.
There are options for using Simple Moving Average (SMA), Linear Weighted Moving Average (LWMA) and Exponential Weighted Moving Average (EWMA).
SMA: all observations in the window are equally weighted for calculating the mean.
LWMA: weights decrease in arithmetical progression. The observations directly next to a central value i, have weight 1/2, the observations one further away (i2,i+2) have weight 1/3, the next (i3,i+3) have weight 1/4, ...
EWMA: uses weighting factors which decrease exponentially. The observations directly next to a central value i, have weight 1/2^1, the observations one further away (i2,i+2) have weight 1/2^2, the next (i3,i+3) have weight 1/2^3, ...
Vector (vector
) or Time Series (ts
) object (dependent on given input at parameter x)
Steffen Moritz
na.interpolation
,
na.kalman
, na.locf
,
na.mean
,
na.random
, na.replace
,
na.seadec
, na.seasplit
1 2 3 4 5 6 7 8 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.