title: Baffling results from tsclean (forecast package)
body: <p>I'm trying to batch process a large number of time series which contain both outliers and missing values. The tsclean function has worked fantastically, but occasionally produces very strange and problematic results that I'd like to understand so I can include logic to avoid them. Here is such a result:</p>
  
  <pre><code>data &lt;- c(2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, NA, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4.3, NA, NA, 1, 1, 1, 1, 1, 1, NA, NA, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, NA, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, NA, NA)
  ts &lt;- ts(data, frequency = 52)
  ts_cleaned &lt;- tsclean(ts)
  </code></pre>
  
  <p>A rounded output of ts_cleaned:</p>
  
  <pre><code>0, -48, -35, -31, -27, -24, -20, -17, -14, -12, -10, -7, -6, -4, -2, -1, 0, 1, 2, 2, 3, 3, 2, 2, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 2, 2, 1, 1, 1, 1, 1, 1, -7, 18, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 0, 1, 1, 1, 2, 3, 4, 6, 7, 9, 11, 13, 18, 19, 22, 24, 28, 31, 35, 39, 50, 90, 2
  </code></pre>
  
  <p>This obviously looks nothing like the original data and leads to big problems when forecasting. What can I do to avoid this at a programatic level?</p>