0

I want to detecting outlier some window time. I use locate.outlier from tsoutliers and also make some additional code for cutting the data. For the illustration, i have 5000 data simulation, the purpose is to detecting 500 data and modelling it for outlier detection to entire data. If first 500 data was free from outlier, i continue to widening data into next one or 501 then detecting outlier and modelling it, and same to 502-4501 data. I have following code.

#Outlier Detection

#Additional Outlier Infront with length #500 and widening window #1
cut=seq(500,5000,1)

#model-1
prediction=matrix(nrow=length(cut),ncol=300)
for (i in 1:100)
{
  print(i)
  dataa.cut=cbind(as.matrix(data1.ara[1:5000,i]),c(1:5000))
  for (j in 1:length(cut))
  {
    print(j)
    dataa.small=dataa.cut[1:nrow(dataa.cut),1]
    if (j!=length(potong))
    {dataa.small=dataa.cut[(nrow(dataa.cut)-cut[j]+1):nrow(dataa.cut),1]}
    fit=auto.arima(dataa.small,stationary=T,allowmean=F)
    resid=residuals(fit)
    pars=coefs2poly(fit)
    out=locate.outliers(resid,pars)$ind
    if (length(out)>0)
    {
      for (k in 1:length(out))
      {
        prediction[j,k+3*i-3]=nrow(dataa.cut)-cut[j]+out[k]
        dataa.cut=dataa.cut[-(nrow(dataa.cut)-cut[j]+out[k]),]
      }
    }
  }
  write.table(prediction,"d://prediksi_AO_depan_Pelebaran_1_500_Model1.csv",dec=".",sep=",")
}

and the following error is

Error in dataa.cut[(nrow(dataa.cut) - (cut[j] + 1)):nrow(dataa.cut),  : 
  only 0's may be mixed with negative subscripts

How can I make this work well?

0 Answers0