The function computes the following temporal averages of after-before differences around key days calculated from a time series:
$$\bar D(I)=\frac{1}{n(I)}\sum_{i\in I} D_i$$
where $I$ is a set of key days, $n(I)$ is the number of key days in $I$, and $D_i$ is an after-before difference computed for each key day $i$ (see below and in after.minus.before function). If operator = "dmv" (difference of mean values), the raw values $y_{i-K},\ldots,y_{i+K}$ of the time series are used to compute the difference:
$$D_i=\left(\frac{1}{K}\sum_{k=1}^K y_{i+k}\right) - \left(\frac{1}{K}\sum_{k=1}^K y_{i-k}\right)=\frac{1}{K}\sum_{k=1}^K (y_{i+k}-y_{i-k}),$$
where $i$ is the date of the key day, $K$ is the number of days considered around the key day (specified when data is provided).
If operator = "dmpiv" (difference of means of positive indicator values), the raw values $y_{i-K},\ldots,y_{i+K}$ are used to compute the difference:
$$D_i=\left(\frac{1}{K}\sum_{k=1}^K 1(y_{i+k}>0)\right) - \left(\frac{1}{K}\sum_{k=1}^K 1(y_{i-k}>0)\right)=\frac{1}{K}\sum_{k=1}^K {1(y_{i+k}>0)-1(y_{i-k}>0)},$$
where $1(\cdot)$ is the indicator function.
If turning.year = NULL, the function computes $\bar D(I)$ where $I$ is the set of all key days in the whole time series.
If turning.year is a numeric vector, for each value $t$ in turning.year the function computes $\bar D(I)$ with $I$ equal to the set of key days in the whole time series, in the time series before $t$ and in the time series after $t$. The function also computes, for each value $t$, the difference between the temporal averages of after-before differences after $t$ and before $t$.