Statistics for time series trend in R Suppose I have a trend such as the following. Here is some code I wrote to generate fake data:
rm(list=ls(all=T))
set.seed(10)
fake.means = c(9,9,8,6,5,4,5,6,4,6,6,5,4,5,4,6,5)

df = data.frame(m=fake.means,sd=NA,N=NA)
for(i in seq(1,nrow(df))) {
  df$N[i] = sample(seq(10,50),1)
  df$sd[i] = sample(seq(0.1,2,by=0.1),1)
}
df$se = df$m/sqrt(df$N)

x = seq(1,17)

plot(x,fake.means,ylim=c(0,15))
lines(x,df$m,lwd=3)
lines(x,df$m+2*df$se,lwd=2)
lines(x,df$m-2*df$se,lwd=2)

polygon(c(x, rev(x)), c(df$m+2*df$se, rev(df$m-2*df$se)),col = rgb(0,255,0,255/2,maxColorValue = 255), border = NA)

It generates the following plot:

Suppose I want to run some statistics to see if this trend is dependent on time (the x-axis). What would be the best thing to use and what would be the best way to do this in R? My initial thought was an ANOVA, but I'm not sure that's the best choice. I'd like to separately be able to run statistics on the first data points to demonstrate statistically that there is in an initial decline. Any suggestions? I appreciate your help in advance!
 A: Your 17 data points suggests the need for a hybrid model incorporating not only memory (ARIMA) but an adjustment for 1 or more data points that do not follow the ARIMA regimen. Here is what might be a "useful model"  using AUTOBOX ( R version is available) , a piece of software which I have helped to develop that speaks to the challemges you raise. Since this data is relatively trivial in it's complexities there are some free remedies in R including auto.arima which might help you in this simple case. The problem with auto.arima is that it doesn't challenge the exceptional values but believes them and then gets confused as it attempts to form an ARIMA structure.
. The issue/objective is plain and clear ... determine the best composite between memory and deterministic structure. Here is another view of the model  .
THe Actual/Fit and Forecast graph is promising . and the Actaul/Cleansed graph is informative  . The plot of the residuals suggest sufficiency with 17 points . You can only do so much with 17 points and 13 degrees of freedom ! I suggest that you try different remedies ( R software solutions) on this data and then increasingly become more aggressive in simulating real-world data with level shifts , time trends , changing error variance , changing parameters , pulses , seasonal pulses et al and see how that works out for you. This can also be done while incorporating effects of X (eXogenous series).
The confidence limits on the forecast reflect re-sampling of the model errors  possibly incorporating future anomalies .
Model expressed as pure right-hand side equation
P.S. For pedagogical purposes, I specified a TREND MODEL (deterministic trend) and rejected any and all possible modifications and obtained the following simple/inadequate solution  . As another example of what not to do , I specified a sytochastic trend model ... first differences plus constant .. and obtained an equally poor soultion ..
Following the request for a specific naive procedure . Assuming 1 and only 1 trend and no step shifts ....
Deterministic Trend ; Y(t)= B0+ B1*T + e(t) where T is the counting numbers (1,2,..T) and e(t) is the errror process and B0 and B1 are the least squares coefficients.
Stochastic Trend  ;   Y(t)= Y(t-1) + B2 + e(t) and e(t) is the errror process and B2 is the least squares coefficient.
See @RHARDY comments Are seasonal differencing and polynomial trends interchangeable?
add a comment |  show 3 more comments
