The t-test
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)
Very nice and interesting post! I didn’t know the anecdote about the Student name.
Thanks!
Thank you, very useful.
Nice Post. You probably don’t drink Guinness.
Good old Gossett. I have had Guiness in Ireland – it’s so much better than here in the USA that I no longer drink it here
You referenced an earlier article on when to use means. Which article were you talking about specifically? I’m not sure using the mean is appropriate and I’m quite sure my situation requires something other than a t-test, but it’s been long enough that I’m not sure what I should be using.
Interesting about Guiness as I’ve heard that from people I know who have traveled to Ireland…something in the shipping that changes the flavor or something along those lines.
Hi Tom
I was talking about this article
thanks
Peter
Excellent! Thanks Peter!
Please, who can say to me – where is the difference between ANOVA and T test??? when to use anova and when t test???
Thank you very much in advance.
waiting impatiently for any possible response!
t-test is used when you have only two groups; ANOVA is used for more than two groups. Really, you can use ANOVA even with only two groups, it will be identical to the t-test, but no one does this and it will get you looked at strangely.
Hi Tom!
I need to compare the height and weight of my 42 paticipants, these are my only options: t-test, annova, wilcoxon, and mann-whitney.
What do you suggest should I use?
Thanks.
I’m not sure who Tom is.
What do you want to compare the height and weight to? Why are those the only options?
Peter
Respected sir/madam,
I know about your valuable information regarding t-test analysis,
i already calculate the P-valu, at 0.05 & 0.01 level, just tell me please how it will compare in given table value if above the level or below the level of significance mention above.
please reply early as possible
thank you.!
I’m sorry but I do not understand your question
I would like to test the average number of lizards that are found on different rock types , different substrate colours and different temperatures? I would like to ascertain which ones they prefer, can i use a t-test or ANOVA?
Hi Missy – you probably want ANOVA/regression
i have made an achievement test on geography which is not standardised.applied it to 40 boys and 40 girls of four different schools. Should i use t test to compare the achievement of boys or girls. what test is suitable to test the significanr differences of both sexes
Sounds like you need a t-test, although you might want regression or even a mixed model
Hi Peter,
Cool post.
I was just wondering am I doing right on the test application or not, so you could guide a bit. I have 23 different targeting clones (divided in 3 groups) in which a certain gene is expressed and I have the fold change values of these genes (gene expression values as compared to a control-non expressed gene.)
So, in simple words, a list of 23 experiments (clones) in 3 groups for a same sample (gene), but the values vary a lot among groups. So, I wanted to apply t-test to check if the change among the groups is significant or not.
What could I use.
Thanks,
Sukhdeep Singh
Peter – at the risk of straining your evident generosity in providing free advice, may I ask for your help? I am collecting data regarding ~10 clinical parameters, incorporating a mix of numerical and non-numerical data, with some parameters being graded in intensity on a scale of 0-4. I would like to interrogate the data to identify, both per patient and in the entire population of studied patients, correlations between parameters and groups of parameters. For example: for a given patient/group of patients , does intensity of parameters a,b,c [individually or as a group] significantly correlate with disease remission [or relapse]; does the correlation only exist / become stronger when patients tick / stop ticking the box for non-numerical category x; etc etc. Is this something you could help with?
Hi Nick – well, my generosity only goes so far. When things get too complex, I ask people to hire me.
In your case, yes, I could help, but it would be beyond the scope of my free advice.
Hi Peter, I would like to test the perception of consumers in online advertising, what well i use? How about if I will rank the type of online advertisement: video add, email add, display add & pop-up? Thanks a lot!
Probably some kind of regression analysis.
Hello Sir Peter, i would like to test prevalence of disease (hydatid cyst)in our local hospital.After the collection of my data, i would like to compare the non-infected as well as infected patients.i also want to compare the Sex wise(males/females) and Age wise difference.please what test is suitable for me?
Sounds like you want logistic regression
Hey. I want to investigate whether payrolls has had an significant increase in year 2005 compared to year 2000 ? I have around 30 club’s payrolls. Could I just use the T-test to investigate this ?
Probably. A paired t-test would be one approach
But when I have to enter which Tail and which Type I want to use (1,2 or 3) which do I use ?
You want whichever option refers to a two-tailed test. I don’t know what software you are using, this could be option 1 2 or 3
I am using the Microsoft Excel and I want to see if there’s a significant change in the payrolls for compared to 2000 and 2005. I just don’t know which option on the tails and which type number
does some one knows why is better to use T test in secondary Analysis?
Thanks
It isn’t. Or, at least, not necessarily
Peter
I would like to test the effect of trust and strong tie between transferer and reciever of electronic word of mouth through Facebook on purchasing decision
Probably logistic regression
A t-test is only for two groups; with more than two, you need ANOVA/regression (really the same thing). But with the type of data you have, you probably need something much more sophisticated. I’m not expert on gene data, but it’s a whole subfield.