There are quite a few R packages available for nonlinear time series analysis, but sometimes you need to code your own models. Here is a simple example to show how it can be done. The model is a first order threshold autoregression: $$ yt = \begin{cases} \alpha y{t-1} + et & \text{if $y{t-1} \le r$}\ \beta y_{t-1} + \gamma et & \text{if $y{t-1}r$} \end{cases} $$ where $e_t$ is a Gaussian white noise series with variance …