Suppose I have a training dataset, I use auto.arima
(from "forecast" package in R) to fit the training data. As a result I get the lag and integration orders $(p, d, q)$ and the corresponding coefficients $\psi_i$ and $\theta_i$.
ytrain = c(0.435477843, 0.435394762, 0.195528995, 1.451623315, 1.740084831 2.379904714, 1.092366508, 0.001031411, 0.592164090, 0.670323418)
fit <- auto.arima(ytrain)
Now I have new data
ytest = c(-0.1349199 0.9001208 -0.5171740 -0.9958452 0.4125953 -0.3320575 0.1633313 0.2890109 -0.4284824 0.7902680)
I want to fit this new data by using the model from training data (using the same $(p, d, q)$ and also the same corresponding coefficients). I.e. I want to use the model I have from ytrain
to make prediction based on ytest
. As a result I can know if there are any points in the new data looking like anomaly points (compared to the training data)
I have searched long time and haven't find a R function to implement it. I know I can compute this by hand, e.g. for ARMA(1,2):
$$\hat{Y}_n = \hat{\mu} + \hat{\psi}_1 Y_{n-1} - \hat{\theta}_{1} \epsilon_{n-1} - \hat{\theta}_2 \epsilon_{n-2}.$$
But if I do this, I am not sure how to start to get $\epsilon_1 = Y_1 - \hat{Y}_1$ and $\epsilon_2 = Y_2 - \hat{Y}_2$ to start since I don't have $\hat{Y}_1$ and $\hat{Y}_2$.
- Could anyone suggest an R function for doing this? Or if not,
- Could anyone help me with this question if there is no R function doing this?