The **t-test** is a statistical test of whether two sample means (averages) or proportions are equal. It was invented by William Sealy Gosset, who wrote under the pseudonym “student” to avoid detection by his employer (the Guinness Brewing Company). Guinness prohibited publications by employees, because another employee had divulged trade secrets in writing.

There are also one-sample versions of a the t-test, to tell if a sample has a mean equal to some fixed value, but these are relatively little used.

**When to use a t-test**

A t-test can be used to compare two means or proportions. The t-test is appropriate when all you want to do is to compare means, and when its assumptions are met (see below). In addition, a t-test is only appropriate when the mean is an appropriate when the means (or proportions) are good measures. See my earlier article for guidance on when to use the mean.

**Matched and unmatched t-tests**

There are two forms of the t-test. In the unmatched t-test, or independent t-test, it is assumed that the two samples are independent. In non-technical language, two samples are independent when knowing something about one does not affect what we know abou the other. For example, the average heights of men and women, drawn randomly from a population, are independent, since knowing the height of a particular man tells us nothing about the height of any particular woman. In a matched t-test, the two sample are not independent; for example, the heights of husbands and wives are not independent, since taller men may be married to taller women. More obviously, the length of people’s right and left feet are dependent, because knowing the size of a right foot tells us a lot about the size of the left foot.

**Assumptions of the t-test**

As noted above, the independent samples t-test assumes the two samples are independent. In addition, both forms of the t-test assume that the variances of the two populations are equal. There are good ways to adjust for unequal variances, provided that the sample sizes of the two

samples are approximately equal. However, if the variances are very different and the sample sizes are different, then the t-test is not a good measure. In addition, as noted above, the t-test only makes sense when the mean makes sense.

**If not the t-test, then what?**

If the t-test is not appropriate, then one alternative is a nonparametric test, such as Wilcoxon’s test. Another alternative is a permutation test, or a bootstrap. In my opinion, all three alternatives ought to be used more often.

**The t-test in SAS**

Suppose one wishes to test if men are heavier than women in a given population. If you sample 5 men and 5 women at random, you might get something like this:

Men: 140 180 188 210 190

Women: 120 190 129 120 130

You could read that into SAS® using

data ttest;

input sex $ weight @@;

datalines;

M 140 F 120 M 180 F 190 M 188 F 129 M 210 F 120 M 190 F 130

;

run;

and then run a t-test by using

proc ttest data = ttest;

class sex;

var weight;

run;

**The t-test in R**

In R, one could read the same data in using

sex <- c(rep(‘M’, 5), rep(‘F’, 5))

weight <- c(140, 180, 188, 210, 190, 120, 190, 129, 120, 130)

and then run a t-test using

t.test(weight~sex)

The output looks like

Welch Two Sample t-test

data: weight by sex

t = -2.4982, df = 7.851, p-value = 0.03758

alternative hypothesis: true difference in means is not equal to 0

95 percent confidence interval:

-84.364290 -3.235710sample estimates:

mean in group F mean in group M

137.8 181.6

Which is terser than the SAS output, but says essentially the same thing. However, by default, R uses the Welch t-test, which does not assume the variances are equal. To get the test with the assumption, you would use

t.test(weight~sex, var.equal = T)

I specialize in helping graduate students and researchers in psychology, education, economics and the social sciences with all aspects of statistical analysis. Many new and relatively uncommon statistical techniques are available, and these may widen the field of hypotheses you can investigate. Graphical techniques are often misapplied, but, done correctly, they can summarize a great deal of information in a single figure. ** I can help with writing papers, writing grant applications, and doing analysis for grants and research.**

** Specialties:** Regression, logistic regression, cluster analysis, statistical graphics, quantile regression.

You can **click here to email** or reach me via phone at 917-488-7176. Or if you want you can follow me on Facebook, **Twitter**, or LinkedIn.

First, you can’t analyze the effect of anything on anything in an observational study – at best, you can establish association

Second, you probably want a longitudinal design here, with measurements at at least 3 time points on each person. Then you can use a multilevel model to analyze the data.

Dear Sir, Can you please confirm whether I can use t tests in the following situation? To test whether there is a relationship between the education levels of CEOs (bachelors, masters, PhDs ) and firm performance? I know t tests have two groups but there are 4 groups in the case given above. However, I could say that there are only two groups in the case given above if I refer to the groups as terminal degrees and firm performance. I am a bit confused about this, can you provide some expert conclusion? Thank you,

No. You should use regression, not t tests.

As t-test required equal variance assumption, but in practical is it possible to have equal variance of two sample?

Thank you

Aboli

The usual t-test assumes approximately equal variances but there are variations that relax this a bit. Variances are never exactly equal, but they can be close. If the distributions are very dissimilar, you should use a different test.

Hello, I am trying to figure out which statistical test to use for this question: it’s given two sets of data and the question is “do they show a difference in soil depth under the mounds compared to not being under a mound?”

Would i use a t-test to investigate if there’s a difference?

Thank you

Hello, I am trying to figure out which statistical test to use for this question: it’s given two sets of data and the question is “do they show a difference in soil depth under the mounds compared to not being under a mound?”

Would i use a t-test to investigate if there’s a difference?

Thank you

Yes, you could do that.

I am trying to understand when do u sue one tail t-test or when to use two tailed test . please make it simpler to understand .

The simple answer is to never use one tailed.

Hi,

I am comparing several means derived from separate experiments. Height difference in plants grown in light and dark.

I am confused as to what T-test to use. I am going round in circles arguing the different points with myself.

Any help would be appreciated.

Thanks in advance

Hi Liz

This sounds like independent samples t-test, unless the plants in the light and dark were somehow matched to each other.

Hi sir, I am confused whether 2-sample t-test is inappropriated. In the question it says the t-test is inappropriated becuase one of the key assumptions is violated.

The experiment is

A consumer watch-dog laboratory organizer wanted to investigate whether a fuel treatment that

was advertised to reduce fuel consumption actually worked. They used 20 different vehicles of

differing makes and sizes. For each vehicle they drove 100km around a test track, using either

untreated or treated fuel (allocated at random), and recorded the amount of fuel used. They then

repeated the experiment using the other fuel type for each vehicle.

vehicleID ID number of the vehicle (1-20)

standard Litres of untreated fuel used to drive 100km

modified Litres of treated fuel used to drive 100km

I cannot find what the key assumption is…

Any help would be appreciated.

The key assumption is that the data are not independent. You need a paired t-test.

Hi Peter Firstly, thanks, this website has really helped me. I have pre and post training data for 200 participants, which I could match up in pairs (in excel) and do a \’paired 2 sample for means\’ t-test, this is how it is referred to in Excel. But I also have a lot of students who either filled in the pre-training questionnaire or the post-training questionnaire, but not both, if I include this this group I will have data from 300 students, that is, about 190 pre-training questionnaires and 110 post-training questionnaires. Should I work with all the data and do an independent samples t-test?

If you have only that data, or only know about t-tests, then I think you have to stick to the paired test on the 200. But if you have more variables you could do multiple imputation. And if you know more methods, some sort of mixed model might be good, depending on what you are trying to find out.

Hello, I have two datasets. The first has a sample size of 500 and the second has a 1000 respondents. I would like to compare the two datasets based on variable x. The mean of variable x in sample 1 is 2.50. In sample 2 the mean is 2.72. I need to statistically compare and see if the difference is significant. T-test would be appropriate for this, right?

Yes. That’s correct.

Good afternoon.

I am doing a retrospective cohort study that is looking at admissions requirements and performance in a graduate program. Specifically, the purpose of my study was to identify if there were any difference in academic performance between students with prerequisite course repeat and students without prerequisite course repeat. Academic performance was measured by GPA, and repeating a prerequisite was measured as Yes/No (1/0) using SPSS.

Would I use a Pearson Correlation, or is a t-test more appropriate?

Correlation doesn’t work for this at all. A t-test is what you want.

I have a fifty participant data set. I want to identify the relationships between drug of choice (categorical) and mental health issues (categorical). Each variable has a set of values ranging for 1-15 and 1-13. What test could i run. I thought Chi square, but my fifty participants is not enough i think. Would your recommend using alternative tests? thank you.

I have a fifty participant data set. I want to identify the relationships between drug of choice (categorical) and mental health issues (categorical). Each variable has a set of values ranging for 1-15 and 1-13. What test could i run. I thought Chi square, but my fifty participants is not enough i think. Would your recommend using alternative tests? thank you.

There are exact versions of chi-square, but they can take a lot of computer time.

If you expect a difference in the data, do you use a paired or unpaired T test, and if you do not expect a difference in the data do you use a paired or unpaired T test? Thank you

That has nothing to do with it. You run a paired t-test if the data are paired. If not, you run unpaired

Peter

Message…

Hello Peter! and thanks so very much for all the help you give to others. I am currently taking a research class and I am not sure which test to use. My hypothesis is that obese and overweight patients do not have healthy outcome after being stigmatized by society including health care workers. So I will have two sets of data, before and after. What test should I use?

Before and after what?

Hello,

I am evaluating a summer bridge program at a university. I now realize I should have, but at the time, I didn’t use any kind of identifiers to match each student’s pre-assessment to their post-assessment. Further, many students who completed the initial assessment were not present to complete the assessment at the end of the program and some who completed the post were not present to complete the initial assessment on the first day of the program. As such, I don’t think I can use a paired samples t-test on this data. Is there anything terribly wrong with treating the pre and post data as independent groups and running an independent samples t-test, if the goal is just to get a rough idea about whether scores changed on average for students who completed the pre assessment versus those who completed the post assessment?

Hello,

I am evaluating a summer bridge program at a university. I now realize I should have, but at the time, I didn’t use any kind of identifiers to match each student’s pre-assessment to their post-assessment. Further, many students who completed the initial assessment were not present to complete the assessment at the end of the program and some who completed the post were not present to complete the initial assessment on the first day of the program. As such, I don’t think I can use a paired samples t-test on this data. Is there anything terribly wrong with treating the pre and post data as independent groups and running an independent samples t-test, if the goal is just to get a rough idea about whether scores changed on average for students who completed the pre assessment versus those who completed the post assessment?

Hi Lisa

The problem is that your errors are not independent. In addition, the students who dropped out are probably not a random group from the ones who started. So, anything you do will have some serious problems.

Sorry

Peter

What type of t-test should I use when I am comparing the means of the stomatal conductance of 5 plants in the light to the mean stomatal conductance of 5 plants in the shade. The independent variable is days because the stomatal conductance for all plants were measured over the course of 5 days.

Hi Ashlyn – no, the independent variable is location (sun vs. shade). You want an independent samples t-test.

Peter

I have to data sets. Control group and Procalcitonin guided group (PCT-G). Control group received antibiotics for normal duration. PCT-G received antibiotic guided by procalcitonin lab values. What type of t-test should I use. Paired two sample for mean or two sample assuming equal variance. It is randomized controlled trial.

Thanks

I have to data sets. Control group and Procalcitonin guided group (PCT-G). Control group received antibiotics for normal duration. PCT-G received antibiotic guided by procalcitonin lab values. What type of t-test should I use. Paired two sample for mean or two sample assuming equal variance. It is randomized controlled trial.

Thanks

It’s not paired unless they are teh same people, which seems unlikely or even impossible. Whether they have equal variance is something that has to be evaluated. Indeed, it’s not clear that you want any sort of t-test at all – it depends on what you are trying to find out and what your dependent variable is.