# How do you calculate sample variance for the difference between outcomes under two experimental conditions?

Suppose we have a group of volunteers who we each ask to undertake a task under two different conditions. $X_i$ is the outcome for the $i^{th}$ volunteer under the first condition, $Y_i$ the outcome under the second condition. Let $Z$ be the difference between $X$ and $Y$, $Z_i=X_i-Y_i$.

There are two ways to calculate the sample variance of $Z$. One can either do it directly from the $Z_i$, working out $$\sum_{i=1}^n (Z_i-\bar{Z})^2/(n-1),$$ or one can calculate the sample variances $\sigma_X^2$ and $\sigma_Y^2$ of the two outcome variables and then use $\sigma_X^2+\sigma_Y^2$ as your sample variance for $Z$.

Which should one use? Are there conditions under which one should be used rather than the other, or are there assumptions that are required before either should be used? In general they give different answers, which will have an effect if you for instance use the sample variance of $Z$ in calculating a confidence interval for the mean of $Z$.

Your formula $\sum_{i=1}^n (Z_i-\bar{Z})^2/(n-1)$ is the correct formula for sample Var(Z).
$Var(Z) = Var(X - Y) = Var(X) + Var(Y) - 2Cov(X,Y)$
Your formula $\sigma_x^2 + \sigma_y^2$ is missing the $-2Cov(X,Y)$ term, and would be correct only if $Cov(X,Y) = 0$, i.e., if $X$ and $Y$ were uncorrelated.
Given that $X_i$ and $Y_i$ for a given $i$ correspond to the same individual, it is not surprising that $X$ and $Y$ could be correlated, as is apparently the case in your data.