Why can't my (auto.)arima-model forecast my time series? For testing I generated a very simple time series with a clear recurring pattern. I expected that auto.arima will generate a model, that can forecast that pattern, but óbviously it doesn't. Can anyone give me some hints how I can improve the model in order to predict that pattern correctly?
library(forecast)

ts<-c(1,1,1,1,1,0,0,1,1,1,1,1,0,0,1,1,1,1,1,0,0,1,1,1,1,1,0,0,1,1,1,1,1,0,0,1,1,1,1,1,0,0,1,1,1,1,1,0,0,1,1,1,1,1,0,0,1,1,1,1,1)
fit <- auto.arima(ts)
plot(forecast(fit,h=20))


Thanks!
 A: Your both examples concern with deterministic time series, with no noise and no trend. Deterministic time series, with no trend is not really the kind of data that ARIMA was designed for (see this question to learn more on ARIMA assumptions).
Actually to forecast future trend given your data what you could do is simply to take averages of different time lags and then repeat them in the same order. The problem in here is to determine the number of lags to use, that is, to find out the length of the window that repeats itself. This could be simply achieved, using sum of squared errors or other error measure. If you define average $k$'th lag value as
$$ \overline x_{(k)} = \frac{1}{N/K} \sum_{i=0}^{(N/K)-1} x_{k+i \times K} $$
and sum of squared errors is
$$ \mathrm{SSE} = \sum_{k=1}^K  \sum_{i=0}^{(N/K)-1} \left( x_{k+i \times K} - \overline x_{(k)} \right)^2 $$
then you can use SSE to choose the best window size. Below you can find an example in R.
tsPattern <- function(x, kmax = ceiling((length(x)/2))) {

  stopifnot(is.numeric(x))
  kmax <- min(round(length(x)/2), kmax)

  predPattern <- function(x, k) {
    n <- length(x)
    pattern <- rep(1:k, times = ceiling(n/k), length.out = n)
    pred <- rep(tapply(x, pattern, mean), times = ceiling(n/k), length.out = n)
    as.numeric(pred)
  }

  out <- NULL
  for (k in 1:kmax) {
    xhat <- predPattern(x, k)
    out[k] <- sum((x - xhat)^2)
  }

  list(fitted = predPattern(x, which.min(out)),
       sumsq = which.min(out))
} 

ts<-c(1,1,1,1,1,0,0,
      1,1,1,1,1,0,0,
      1,1,1,1,1,0,0,
      1,1,1,1,1,0,0,
      1,1,1,1,1,0,0,
      1,1,1,1,1,0,0,
      1,1,1,1,1,0,0,
      1,1,1,1,1,0,0,
      1,1,1,1,1)

ts2 <-rep(c(1,1,2,3,4,4,5,5,6,5,5,4,3,3,2),10)
ts2 <- ts2 * round(runif(length(ts2), 0.95, 1.0), digits=2)

tsPattern(ts, 10)
tsPattern(ts2, 20)

Below you can see the results plotted (red points are estimated values, lines are actual data). 

This primitive approach works very good for your examples of deterministic time series with no trend and no noise, it would fail however with real life data, i.e. exactly in such cases as ARIMA (and other similar time-series methods) were designed for. Below you can see results of using this method and auto.arima for real life data (WWWusage dataset in forecast library).

A: A bit late, but you can specify your frequency and tell arima that you have seasonality:
library(forecast)

ts<-c(1,1,1,1,1,0,0,1,1,1,1,1,0,0,1,1,1,1,1,0,0,1,1,1,1,1,0,0,1,1,1,1,1,0,0,1,1,1,1,1,0,0,1,1,1,1,1,0,0,1,1,1,1,1,0,0,1,1,1,1,1)

ts <- ts(ts, frequency = 7)
fit <- auto.arima(ts, D = 1)
plot(forecast(fit,h=20))

This works as desired and ARIMA finds the structure.

