# R : arima : plotting regression line of autocorrelated time-series data when d > 0

I'm interested in determining both the slope regression coefficient and plotting regression lines for autocorrelated time-series datasets of rainfall. Specifically, I'd like to identify the best approach in R that would allow me to visualize the regression line on the original (undifferenced) time-series plot when I need to difference the data to remove stationarity (i.e, when d>0 in an arima model).

As a start, I'm exploring the use of auto.arima (from the forecast package) and sarima (from the astsa package) which can output regression coefficients in the presence of autocorrelation.

For example:

1. Using auto.arima. The 'drift' of -5.009 represents the slope (see http://robjhyndman.com/hyndsight/arima-trends/)

> min.ar <- auto.arima(dec.yr.mmin$min_prcp) > summary(min.ar) Series: dec.yr.mmin$min_prcp
ARIMA(1,1,0) with drift

Coefficients:
ar1    drift
-0.5138  -5.0089
s.e.   0.2465   5.7986

sigma^2 estimated as 949:  log likelihood=-57.82
AIC=121.64   AICc=124.31   BIC=123.34

Training set error measures:
ME     RMSE      MAE       MPE     MAPE      MASE       ACF1
Training set -0.9479987 28.52129 23.83494 -2.484233 16.12547 0.7957998 -0.2617352

2. Using sarima to fit the model and output the slope

  > fit.min <- sarima(dec.yr.mmin$min_prcp, 1,1,0, reg=dec.yr.mmin$decade)
initial  value 3.542448
iter   2 value 3.488927
iter   3 value 3.386967
iter   4 value 3.383464
iter   5 value 3.382408
iter   6 value 3.382051
iter   7 value 3.382024
iter   8 value 3.382020
iter   9 value 3.381925
iter   9 value 3.381925
iter   9 value 3.381925
final  value 3.381925
converged
initial  value 3.400729
iter   2 value 3.399523
iter   3 value 3.399490
iter   4 value 3.399488
iter   4 value 3.399488
iter   4 value 3.399488
final  value 3.399488
converged


3.Output coefficients

      > fit.min$fit$coef
ar1       xreg
-0.5137696 -0.5009045

1. For comparison, this is the output from an OLS regression which may give an incorrect slope due to autocorrelation.

  > m3 <- lm(dec.yr.mmin$min_prcp ~ dec.yr.mmin$decade)
> summary(m3)

Call:
lm(formula = dec.yr.mmin$min_prcp ~ dec.yr.mmin$decade)

Residuals:
Min      1Q  Median      3Q     Max
-45.504  -8.048   1.892  13.650  38.357

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept)        1014.1570   319.9461   3.170  0.00807 **
dec.yr.mmin\$decade   -0.4222     0.1580  -2.672  0.02032 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 23.83 on 12 degrees of freedom
Multiple R-squared:  0.3731,  Adjusted R-squared:  0.3209
F-statistic: 7.142 on 1 and 12 DF,  p-value: 0.02032




The output from sarima identifies the slope coefficient and also intercept when d=0. When differencing is required (e.g., ARIMA (1,1,0) as output above), sarima only outputs the slope.

My question: when d = 1 or more, what approaches in R would allow me to add/visualize the regression line onto the original undifferenced time-series plot. Is it possible to derive the fitted values of the regression line, or derive intercept values from sarima/auto.arima or other package?

• What's the question exactly? You can use fitted.values(m), where m` is the model to extract the in-sample fit to compare to the original data. I'm not sure what you mean by slope and intercept, as a ARIMA(1,1,0) model is not going to be a line. – A. Webb Jul 9 '15 at 15:12