#' Apply autoregression of order 2 on timeseries
#' This function applies autoregression of order 2 using a numeric vector (predicts next value in series given previous 2)
#' @param s A numeric vector representing the series.
#' @param a1 A coefficient of first previous value in the series.
#' @param a2 A coefficient of second previous value in the series.
#' @export
apply_ar_on_ts = function(s, a1, a2){
s_pred = rep(0,length(s))
s_pred[1] = NA
s_pred[2] = NA
for (t in 3:length(s)){
s_pred[t] = a1*s[t-1] + a2*s[t-2]
}
s_pred
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.