# How to calculate the expected value of a time series just from the data

in this question Can stationary time series contain regulary cycles and periods with different fluctuations I was told that stationary time series do not have regular cycles and that having constant cycles implies that the expectation value is not constant. One of the properties of stationary time series is "Expected value is constant for every t".

Now I am wondering why this is the case. Let's have a look at this blue time series: I personally would argue that it has a constant expected value which is just the mean in this case because on average this is the value of the time series. How can I show that this time series in fact does not have a constant expectation value. I do not have any further information about the time series but just the values themselves. How could I calculate the expectation value for every t and show that they are not constant for every t which would imply that this time series is not stationary.

I would like to know just from the time series if this time series is stationary and how I can calculate the expected value (because this is essential for saying whether the time series is stationary or not).

I'd appreciate every further comment and would be quite thankful for your help.

Reminder: As this question is really important for me and I am not entirely satisfied with the answers given so far, I will award a bounty for a more detailed answer. I'll be quite happy for your help.

• This probably boils down to whether you are after an unconditional or a conditional expectation. Conditional expectation would be specific to a given $t$. Unconditional expectation would average across $t$s. (Long-term mean might also be considered; it would be (related to) the unconditional expectation.) I am a bit unsure about the formalities of all this, so I am posting this as a comment rather than an answer. Commented Nov 25, 2020 at 10:42
• Thanks Richard for your answer. According to my search a stationary time series has 3 properties: Expactation value is constant for every t; Variance is constant for every t; Autocovariance is constant for every t; I would like to show that they are violated by the blue line as in two posts I was told that a cyclic time series are not stationary Commented Nov 26, 2020 at 9:35
• Are these things constant for every $t$ (e.g. $\mathbb{E}(y_t)=c_t \ \forall \ t$) or across $t$ (e.g. $\mathbb{E}(y_t)=c \ \forall \ t$)? If across $t$, it looks like this does not hold for your series. Commented Nov 26, 2020 at 9:47
• Thanks Richard for your further answer and effort. I really appreciate it. I just have read the statement "Expactation value is constant for every t". I think it should be for every t. You mentioned "If across t, it looks like this does not hold for your series". How can you calculate that? Commented Nov 26, 2020 at 10:02
• Unless the cycles observed in your series are not representative of the data generating process (DGP) (i.e. just a weird sample), you can model the DGP as containing cycles where $\mathbb{E}(y_t)$ varies with $t$. In the bottom of the cycle, $\mathbb{E}(y_t)$ is low, and at the top it is high. Commented Nov 26, 2020 at 10:57

I would like to know just from the time series if this time series is stationary and how I can calculate the expected value

The "just from the time series" is not working. You need to have some idea about the underlying process that generates the time series.

For instance, the image below shows a time series that is seemingly trend stationary for $$t<0$$ but differs for $$t>0$$.

To know whether a time series is stationary requires not just the data, but also some assumptions about a theory for the process that generates the time series.

Then you can test whether

• The data fulfills the properties for stationarity (e.g. use some test to find out whether the process has a unit roots or not)
• Estimate other parameters of the model (for which there are many different approaches and it depends on your type of time series)
• Predict future values (extrapolate the model along with estimates of the parameters).

Even when the data is not stationary you can still fit a model to it. But it has some problems for some of the fitting methods.

• Thanks Sextus Empiricus for your answer and help (I upvoted your answer). I understand what you say. However, in 2 posts (stats.stackexchange.com/questions/491785/… and (stats.stackexchange.com/questions/496828/…) I was told that time series with cycles can't be stationary and I was literally told that "Contains cycles" is a special form of not having a constant expectation." What is your take on that? Commented Dec 8, 2020 at 9:14
• So if we need further informationen about the time series to decide whether it is stationary or not, then I think you can't immediately rule out just from the data that a time series that contains cycles is not stationary. In fact I would even argue that the blue time series tends to be stationary as it seem so have a constant expectation value when you just look at the data. But of course we can't know this for sure because we do not have any model. Commented Dec 8, 2020 at 9:17
• @PeterBe I generated the time series in this example as a sinus wave plus Gaussian noise. It is not strictly stationary because the expectation is not independent from the time $t$. $$X_t\vert t \sim N(1+\sin(a\cdot t), \sigma^2)$$ However if you subtract the sinus wave component from the time series then what remains is Gaussian noise that is independent of time. $$Y_t = X_t - (1+\sin(a\cdot t))\vert t \sim N(0, \sigma^2)$$ So it is trend stationary. Commented Dec 8, 2020 at 10:58
• Thanks Sextus for your answer. I really appreciate your help. Okay, so it is wrong to say that time series with cycles are generally not stationary. Thanks for this conclusion. Regarding the expectation value I would argue that your plotted time series has a constant expectation value of 1. You can just take the mean and I think that on average the time series produces the value of 1 for all t. Commented Dec 8, 2020 at 11:18
• @PeterBe whether or not time series with cycles are stationary depends on what sort of stationarity you consider. It is not generally stationary because it is not stationary when you use the strict sense of stationarity. Regarding the expectation value, this is not constant if you have cycles. Saying that it is constant would be like saying that the expected outdoor temperature is the same in summer as in winter. Commented Dec 8, 2020 at 11:45

If you by a time series means a concrete series of numbers/observations attached to some time points, then it is neither stationary nor not stationary, neither does it have an expectation (or not!) Those concepts apply only to time series models, that is, some probability model for a time series.

So by just looking at your blue wavy curve, nobody can answer your question! Such a curve could be generated by a stationary process, but it could also be generated by some nonstationary process. In the comments some argue about strong/weak stationarity, but I think that is irrelevant here. Everything said here applies equally to both.

To advance from here, you could tell us a model, then we can answer ... but more realistically, you do not have a model yet, you have some observations from some phenomenon, an the question should really be if a stationary time series model for that process is reasonable. An answer to that depends on the process, the phenomenon, not just the numerical data.

• a monthly time series of some economics type ... seasonal variation is often seen, sales of christmas trees, for instance, is cyclical, with maximum around the same time each year ... not stationary

• some natural phenomena might have dynamically generated cycles (or quasi-cycles). An example could be predator-prey cycles

• some stationary ar(2) models can generate cyclic behavior

To followup on the last bullet point, let us simulate some (stationary) ar(2) model with cyclic behavior. I am following the example used in this excellent discussion of difference between seasonality and a cyclic series (some of the comments to your post indicates that you really have seasonality, not cyclicity.) The simulation is done in R:

set.seed(7*11*13)# My public seed

n <- 250
ar.sim <- arima.sim(list(ar=c(1.147, -0.6)), n)

library(scorepeak)

peaks <- detect_localmaxima(ar.sim, 5)

plot(ar.sim, type="l" )
points(which(peaks) , ar.sim[peaks],  col="red", pch=18)

The red diamonds in the plot indicates the position of local maxima, and looking at the distance between them could be a way to study period/cycle length. But that is to subjective, so we look for some other approach.

The periodogram is the tool of choice here, trying to estimate which fraction of the total variance in the series comes from different cycle lengths:

ar.sim.spec <- spectrum(ar.sim, spans=5)

Usually this is plotted on the log scale, to show better the details also in the low frequency part of the plot. But here we are more interested in seeing where the main contributions to total variance is, and the a linear scale is more appropriate, since then area under the curve is directly proportional to proportion of variance:

plot(ar.sim.spec, log="no",
main="Periodogram (linear scale) for ar.sim")

We can read the main contribution periodicities from the plot. Since period is inverse of frequency:

1/c(0.16, 0.08)
[1]  6.25 12.50
• Thanks a lot kjetil for your answer. In 2 posts (stats.stackexchange.com/questions/491785/…) and (stats.stackexchange.com/questions/496828/…) I was told that time series with cycles can't be stationary and I was literally told that ""Contains cycles" is a special form of not having a constant expectation." Commented Nov 26, 2020 at 9:33
• The drawn blue line clearly has cycles. So I would like to know how I can calculate the expectation value to show that this time series is not stationary as it has a constant expectation value. Commented Nov 26, 2020 at 9:33
• Thanks a lot kjetil for your answer. Any comments to my last responses to your answer? I'd highly appreciate every further comment from you and would be thankful for further help. Commented Nov 27, 2020 at 8:28
• Hi: you have to be careful with the definition of stationarity. weak ( wide sense ) stationarity is just unconditional mean and unconditional variance constant. these do hold for your series. but strong stationarity is that joint distribution is time invariant ( shift the data by some fixed time and joint distribution stays the same ). For a time series with cycles, this is not going to be true so strong stationarity doesn't hold. So the question of stationary, depends on which one is being referred to. Commented Nov 29, 2020 at 5:16
• thank kjetil for your comment and effort. I really appreciate it. Well basically for me it did not matter what the blue line represents. I thought that the definition of stationarity should be independent from the application. But let's say these are the monthly sales of a company or the price of a stock. I would like to know just from the time series if this time series is stationary and how I can calculate the expected value (because this is essential for saying whether the time series is stationary or not) Commented Nov 30, 2020 at 17:13