Student's t-test with a covariate? I am testing the different between some variables $X$ and $Y$ using the Student's t-test. I suspect that there might be a latent variable $Z$ that has an effect on both $X$ and $Y$. How could I control $Z$?
I am using Python for the data analysis.
 A: One common means of controlling for some other covariate would be via regression. Put the X and Y values into the response (DV), and a Y-group indicator (0 if in X, 1 if in Y) as a DV, along with your covariate (or some suitable proxy for it if the variable can't be measured directly) as another DV.
You regress on your covariate and the group-indicator. If there's a difference between X and Y based on the covariate, this will be "adjusted" for by the regession, and significance of the coefficient of the group-indicator will then be a test of a mean-shift between the two groups after accounting for the covariate.

This is sometimes called ANCOVA (unless Z is a factor, in which case it would usually be called ANOVA; you can still do it using regression). 
Some people would formally test parallelism of the two group-lines (by including an interaction between covariate and group-indicator). I think that's wrong-headed (do we believe the hypothesis of no-interaction is exactly true? I don't -- in which case the hypothesis test is a noisy answer to a question we already know the answer to -- surely they're never going to be exactly parallel) ... but don't especially care about. The better question here is "are they close enough to parallel that it doesn't badly impact the properties of the inferences we wish to make?'. Answering that is nearer to measuring an effect size, so a residual display - e.g. residuals vs covariate that distinguishes the groups with symbols or colors - might come closer to addressing that.

However, depending on what you mean by 'latent' in your question, it's possible that you may actually be after something more like an instrumental variable. (There are numerous questions on site on the topic.)
A: By means of t-test you are assessing whether there is a significant difference between two sets of data --- e.g. the realizations of two random variables $X$ and $Y$. When using t-test you are doing a hypothesis test, and you can't control for any variable. To be more specific, when doing hypothesis tests you are not establishing any causal relationship between random variables.
If you want to investigate the effect of a latent variable $Z$ on both $X$ and $Y$, you should rely on a regression analysis. For a deeper analysis on the role and effects of some variables (which can cause a bias in your analysis), you can apply some methods of graphical models.
Here you find a nice IPython Notebook on regression.
