Function to predict values based on a running mean (or another function) of a numeric vector.
runn_mean_pred( indep, dep, pred, runn_mean =11, na.rm =FALSE, exclude_central_value =FALSE, FUN = mean
)
Arguments
indep: numeric vector of independent variables, should be sequential
dep: numeric vector of dependent variables
pred: numeric vector of values to be predicted
runn_mean: number of vector elements to use for calculating the running mean
na.rm: ignore NA values when calculating means. Defaults to FALSE.
exclude_central_value: exclude central value in calculating means. Defaults to FALSE.
FUN: function to be applied. For a running mean, this is usually mean (the default), but other functions can also be specified here (the na.rm parameter won't work then, and the function has to be dependent on one numeric variable only.
Returns
list of two elements, with xcontainingthevaluestobepredictedandpredicted the predicted values
Details
The running mean calculation that underlies the prediction is based purely on the sequence of observed values, without accounting for any variation in intervals of the independent data. This means that the function performs best with regularly spaced independent variables. Note that the function will return NA when asked to predict values that are outside the range of independent values provided as input. The prediction results are computed by linearly interpolating between the running mean values determined for the nearest neighbors of the value that is to be predicted.