The one sample t test is used to compare the mean of a sample to some specific value. You set up a null hypothesis and test it against the alternative hypothesis. The alternative hypothesis can vary, based on whether you are performing a one sided or two sided t test. This post demonstrates how to perform simple one sample t tests in SAS.
Two Sided t Test Example
In the two sided t test case, we test the null hypothesis against the alternative hypotheses . This means that we are not making any assumptions on whether we suspect that the population mean is less than or greater than the hypothesized mean . We only suspect that it is different. First, we assume that the sample comes from a normal distribution. If you want to assess the normality of your data, check out my blog post Fit Continuous Distribution in SAS. Next, we calculate the t statistic as
Next, we evaluate the t statistic in both tales of a T Distribution with degrees of freedom (your sample size) and calculate the p value as the area under the curve in the tails more extreme than our t statistic.
We use PROC TTEST in SAS to assess the null hypotheses in the sashelp.class data set to test whether we can assume that the average height of the students can be assumed to be 60.
proc ttest data=sashelp.class h0=60; sides=2 alpha=0.05; var height; run;
To the right you can see the relevant t distribution for the two sided t test. The red area in the tails under the curve represent the p-value of 0.0624. This means that we reject the null hypothesis . This leds us to accept the alternative hypothesis .
One Sided t Test Example
However, if you suspect that if your null hypothesis does not hold, then the average height of students is either larger or smaller than your hypothesized mean, then you perform a one sided t test. You can do this in PROC TTEST as follows.
proc ttest data=sashelp.class h0=60 sides=u alpha=0.05; where sex='M'; var height; run;
The only difference between the twp PROC TTEST steps is that we specify the SIDES=U in the latter step. This means that now, we test the null hypothesis against the alternative hypothesis . You can see the relevant t distribution along with the t statistic and p value to the right.
You can use the one sample t test to assess whether the population mean is equal to some specified mean using the PROC TTEST. This is the easiest and most obvious way, but there are other procedures, that will yield the exact same result.
For a more thorough introduction to the one sample t test, watch the youtube video Introduction To The One Sample T Test by JbStatistics.
Finally, you can download the entire program from this post here. The code that produces the graphs are included.