Time series autocorrelation with missing years

4 views (last 30 days)
Cecilia Wang
Cecilia Wang on 17 May 2020
Answered: azim on 8 Jun 2020
I have a time series that is missing some years. I want to calculate the autocorrelation function. But autocorr does not allow us to specify a vector for the time points corresponding to the vector we are calculating autocorrelation for.
In other words, if I use autocorr(herbicide_amount), because I only have data for the years 1996, 1997, 1998, 1999, 2000, 2001, 2005, and 2010, the autocorrelation calculated and plotted will consider the herbicide_amount in 2005 to be one lag away from 2001, when it should actually be four lags away, and so on.
Is there a way to make this work? Or am I stuck with using just the data that's available in consecutive years (1996 to 2001)?
I realize that this may be more of a mathematical question than a coding one.

Answers (1)

azim on 8 Jun 2020
did you consider using retime and filling in the time gap in your timetable data. for eg. as per the documentation example:
Time = datetime({'2015-12-18 07:02:12';'2015-12-18 08:00:47';...
'2015-12-18 09:01:37';'2015-12-18 10:03:10';...
'2015-12-18 10:59:34'});
Temp = [37.3;41.9;45.7;42.3;39.8];
Pressure = [30.1;29.9;30.03;29.9;29.8];
TT = timetable(Time,Temp,Pressure)
TT2 = retime(TT,'hourly','spline')
you can read about it on the link mathworks.com/help/matlab/ref/timetable.retime.html
there are many methods for filling in the gaps like spline, mean, linear etc. so you can choose the method which suits your data the best. hope this helps

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!