For these structures, we have used the basic functions ar and arima of the stats package to fit the AR(p) and ARMA(p,q) models, respectively. The users can define their own functions or use other well-known functions that exactly fit the situation at hand.