T-test in the presence of autocorrelation I have a time series data and I would like to check if the sample mean is statistically significantly different from zero. I was going to do the t-test, but the t-test assumes independent data, while my data are heavily autocorrelated (about 40% lag-1 autocorrelation), so my t-stats are also extremely bloated. 
I know I can subsample my data, so that the autocorrelation is minimized. But is there anyway to correct for the autocorrelation of the time series while still using the full data, so that the t-stats and p-value correctly indicates the probability of observing similar mean at random from a zero-mean data? I guess there are some corrections to the sample size, so we can have some "effective sample size" that is smaller than actual sample size.
 A: With model variations like this, it is usually possible to adjust the standard pivotal quantity for the T-test, and perform a test analogous to a standard T-test, by calculating the standard error of your point estimator for the mean, and adjusting your test accordingly.  This may require quite a bit of algebra, but it is usually possible to do with a bit of work.  In this answer we will derive the variance of the sample mean and use this to find the standard error of the sample mean, expressed in its usual fashion but with an adjustment for the effective sample size.  We will then form a quasi-pivotal quantity based on the sample mean that can be used for hypothesis testing.

Variance of the sample mean in an AR(1) model: For an AR$(1)$ model with auto-regression parameter $-1<\phi<1$ you have (using some algebra shown in 
Appendix at bottom of post):
$$\begin{equation} \begin{aligned}
\mathbb{V}(\bar{X}_n) = \mathbb{V} \Big( \frac{1}{n} \sum_{t=1}^n X_t \Big) 
&= \frac{1}{n^2} \sum_{t=1}^n \sum_{r=1}^n \mathbb{C}(X_t,X_r) \\[6pt]
&= \frac{\sigma^2}{n^2} \sum_{t=1}^n \sum_{r=1}^n \frac{\phi^{|t-r|}}{1-\phi^2} \\[6pt]
&= \frac{1}{1-\phi^2} \cdot \frac{\sigma^2}{n^2} \sum_{t=1}^n \sum_{r=1}^n \phi^{|t-r|} \\[6pt]
&= \frac{1}{1-\phi^2} \cdot \frac{\sigma^2}{n^2} \Bigg[ n + 2 \sum_{k=1}^{n-1} (n-k) \phi^k \Bigg] \\[6pt]
&= \frac{n - 2\phi - n\phi^2 + 2\phi^{n+1}}{(1-\phi^2)(1-\phi)^2} \cdot \frac{\sigma^2}{n^2} \\[6pt]
&= \frac{1}{n} \cdot \frac{n - 2\phi - n\phi^2 + 2\phi^{n+1}}{n(1-\phi)^2} \cdot \frac{\sigma^2}{1-\phi^2} \\[6pt]
&= \frac{1}{n_\text{eff}(\phi)} \cdot \frac{\sigma^2}{1-\phi^2}, \\[6pt]
\end{aligned} \end{equation}$$
where the "effective sample size" is defined by:
$$n_\text{eff}(\phi) \equiv \frac{n^2(1-\phi)^2}{n - 2\phi - n\phi^2 + 2\phi^{n+1}}.$$
When $n=1$ we have $n_\text{eff}(\phi) = 1$ and as $n \rightarrow \infty$ we have $n_\text{eff}(\phi) \rightarrow n (1-\phi)/(1+\phi)$.  The ratio $n_\text{eff}/n$ is decreasing with respect to $n$ if $\phi > 0$ and is increasing with respect to $n$ if $\phi < 0$.

Standard error and quasi-pivotal quantity: Now that we have the variance of the sample mean, we have standard error:
$$\text{se}(\bar{X}_n) = \frac{1}{\sqrt{n_\text{eff}(\phi)}} \cdot \frac{\sigma}{\sqrt{1-\phi^2}}.$$
The value $\text{se}(X_t) = \sigma / \sqrt{1-\phi^2}$ is the standard error for a single observation in the model.  As we increase $n$ we adjust the standard error by dividing through by the effective sample size.  If you are willing to incorporate the variability of this function from your estimator of $\phi$ as one lost degree-of-freedom, and otherwise ignore its variability, then you can form the quasi-pivotal quantity with approximate distribution:
$$\frac{\bar{X}_n - \mu}{\hat{\text{se}}(X_t) / \sqrt{n_\text{eff}(\phi)}} \sim \text{T}(df = n-2).$$
This allows you to test the hypothesis of zero mean using a standard T-test, with an adjustment for the estimated auto-correlation between the values.  Note that this is a fairly crude adjustment which does not take account of the variability in the estimator for $\phi$.

Appendix - Some mathematical working: Here is the mathematical working for the last step of the above result.  Using the results for sums of geometric sequences we have:
$$\begin{equation} \begin{aligned}
\sum_{k=1}^{n-1} (n-k) \phi^k
&= n \sum_{k=1}^{n-1} \phi^k - \sum_{k=1}^{n-1} k \phi^k \\[6pt]
&= n  \sum_{k=1}^{n-1} \phi^k - \phi \frac{d}{d\phi} \sum_{k=1}^{n-1} \phi^k \\[6pt]
&= n \cdot \frac{\phi-\phi^n}{1-\phi} - \phi \cdot \frac{d}{d\phi} \frac{\phi-\phi^n}{1-\phi} \\[6pt]
&= n \phi \cdot \frac{(1-\phi)(1-\phi^{n-1})}{(1-\phi)^2} - \phi \cdot \frac{(1-\phi)(1-n\phi^{n-1}) + (\phi-\phi^n)}{(1-\phi)^2} \\[6pt]
&= n \phi \cdot \frac{1-\phi-\phi^{n-1} + \phi^n}{(1-\phi)^2} - \phi \cdot \frac{1 -\phi -n\phi^{n-1} +n\phi^n +\phi -\phi^n}{(1-\phi)^2} \\[6pt]
&= \frac{\phi}{(1-\phi)^2} \Big[ n (1-\phi-\phi^{n-1} + \phi^n) - (1 -n\phi^{n-1} +n\phi^n -\phi^n) \Big] \\[6pt]
&= \frac{\phi}{(1-\phi)^2} \Big[ n - n\phi - n\phi^{n-1} + n\phi^n - 1 + n\phi^{n-1} - n\phi^n + \phi^n \Big] \\[6pt]
&= \frac{\phi}{(1-\phi)^2} \Big[ (n-1) - n\phi +\phi^n \Big]. \\[6pt]
\end{aligned} \end{equation}$$
We then have:
$$\begin{equation} \begin{aligned}
n + 2\sum_{k=1}^{n-1} (n-k) \phi^k
&= n + \frac{\phi}{(1-\phi)^2} \Big[ 2(n-1) - 2n\phi + 2\phi^n \Big] \\[6pt]
&= \frac{1}{(1-\phi)^2} \Big[ n (1-\phi)^2 + 2(n-1)\phi - 2n\phi^2 + 2\phi^{n+1} \Big] \\[6pt]
&= \frac{1}{(1-\phi)^2} \Big[ n -2n\phi +n\phi^2 + 2n\phi - 2\phi - 2n\phi^2 + 2\phi^{n+1} \Big] \\[6pt]
&= \frac{1}{(1-\phi)^2} \Big[ n - 2\phi - n\phi^2 + 2\phi^{n+1} \Big] \\[6pt]
&= \frac{n - 2\phi - n\phi^2 + 2\phi^{n+1}}{(1-\phi)^2}. \\[6pt]
\end{aligned} \end{equation}$$
