You are on page 1of 3

help ttest gives help for the ttest

ttest variable name= #


1) One-sample t test

To load the dataset, type sysuse bplong

Sysuse bplong

I hypothesize that the mean of the variable bp is equal to 155 mmHg.

The single sample t-test tests the null hypothesis that the population mean is
equal to the given number specified using the option bp == 155

For this example, we will compare the mean of the variable bp with a pre-
selected value of 155. 

Based on the results of this test, I fail to reject my null hypothesis that the mean of bp
is not significantly different from 155 mmHg. 

How?

Formal evaluation compares the null hypothesis (Ho), that the mean is 155,
with one of three alternative hypotheses (Ha): that the mean is less than
155, that the mean is not equal to 155 but could be bigger or smaller, and
that the mean is greater than 155. You must pick the alternative hypothesis
you're interested in testing before running the test.

First consider Ha: mean < 155. If the population mean is 155, then the
probability of drawing a sample with a mean of 153 or less, given the number
of observations we have and the standard deviation we observe, is 0.0978
This is greater than .05, so we do not reject the null hypothesis that the
mean is 155

Next consider Ha: mean != 155. If the population mean is 155, then the
probability of drawing a sample that is at least 155 - 153 = 0.62 away from
that mean in either direction is 0.1957 (again, given the number of
observations we have and the standard deviation we observe). This is exactly
twice the probability of the previous hypothesis, though this is obscured by
rounding. The previous hypothesis was a one-tail test (i.e. looking at the
probability that the outcome is out in one of the "tails" of the probability
distribution) while this is a two-tail test (i.e. looking at the probability that
the outcome is in either tail of the distribution). Again the probability is
greater than 0.05, so we do noyreject the null hypothesis that the mean is
155

Finally consider Ha: mean > 155. If the population mean is 155, then the
probability of drawing a sample with a mean that is 153 or greater is 0.9022
(i.e. it's almost certain). This probability is nowhere near less than 0.05, so in
this case we accept the null hypothesis that the mean is 155 rather than the
alternative that the mean is greater than 155.

a. Variable – This is the variable for which the test was conducted.

b. Obs – The number of valid (i.e., non-missing) observations used in


calculating the t-test.

c. Mean – This is the mean of the variable.

d. Std. Err. – This is the estimated standard deviation of the sample mean.  If
we drew repeated samples of size 200, we would expect the standard
deviation of the sample means to be close to the standard error. The standard
deviation of the distribution of sample mean is estimated as the standard
deviation of the sample divided by the square root of sample size:
9.478586/(sqrt(200)) = .6702372.

e. Std. Dev. – This is the standard deviation of the variable.

f. 95% Confidence Interval – These are the lower and upper bound of the
confidence interval for the mean.
95% confidence interval does include 155, so it's looking good for our null
hypothesis.

g. Ho – This is the null hypothesis that is being tested.  The single sample t-
test evaluates the null hypothesis that the population mean is equal to the
given number.

h. t – This is the Student t-statistic.  It is the ratio of the difference between the
sample mean and the given number to the standard error of the mean:
(153.9042– 155) / .8445493 = -1.2975. Since the standard error of the mean
measures the variability of the sample mean, the smaller the standard error of
the mean, the more likely that our sample mean is close to the true population
mean.  This is illustrated by the following three figures.

i. mean: This is the mean being tested. In this example it is the mean of
bp.
ii.
j. degrees of freedom – The degrees of freedom for the single sample t-test
is simply the number of valid observations minus 1.  We lose one degree of
freedom because we have estimated the mean from the sample. 

k. Pr(T < t), Pr(T > t) – These are the one-tailed p-values evaluating the null
against the alternatives that the mean is less than 155 (left test) and greater
than 155 (right test). These probabilities are computed using the t
distribution. Again, if p-value is less than the pre-specified alpha level
(usually .05 or .01) we will conclude that mean is statistically significantly
greater or less than the null hypothetical value.

l.   Pr(|T| > |t|) – This is the two-tailed p-value evaluating the null against an
alternative that the mean is not equal to 155.  It is equal to the probability of
observing a greater absolute value of t under the null hypothesis.  If p-value is
less than the pre-specified alpha level (usually .05 or .01, here the former) we
will conclude that mean is statistically significantly different from zero.  For
example, the p-value for bp is greater than 0.05. So we conclude that the
mean for bp is not different from 155.

Now, suppose you wanted to test the hypotheses that the population mean for the
bp before is the same as the population mean bp after

Note that "Before" and "After" are blue, and not red -- meaning they are labels [and
not strings].)

Use the following two tests to ask whether the mean for the first group is equal to 155
mmHg, or if the mean of the second group is equal to 155 mmHg.

ttest bp==155 if when==1

ttest bp==155 if when==2

You might also like