Stat/Math
Software Support
Software Consulting
Software Availability
Software Price
Contact

User Support
Documentation
Knowledge Base
Education
Consulting
Podcasts

Systems & Services
Cyberinfrastructure
Supercomputers
Grid Computing
Storage
Visualization
Digital Libraries & Data

Results & Impact
Publications
Grants & Grant Info
Events & Outreach
Economic Impact
Survey Results

Vision & Planning
News & Features

# 3. Paired T-test: Dependent Samples

T-tests compare the means of two samples. Two variables may or may not be independent. When each element of a sample is matched to its corresponding element of the other sample, two samples are paired. This paired t-test examines the mean of individual differences of paired measurements and thus is appropriate for pre-post situations. Suppose we want to investigate the effectiveness of a new medicine on lung cancer by checking patients before and after they took the medicine.

The null hypothesis is that the population mean of individual differences of paired observations is D0 (zero unless explicitly specified). If the null hypothesis is rejected, there must be a significant difference (effect) between two samples (pre and post outcomes).

3.1 Paired T-test in STATA

In Stata, you need to list two variables separated by an equal sign. The level(95) option can be omitted. Stata presents summary statistics of two variables and then conducts the paired t-test using the differences of matched pairs. The post mean 186.1944 is 10.1667 larger than 176.0278 before a treatment. But the standard deviation 32.6019 of the difference is also large.

. ttest pre=post0, level(95)
Paired t test
------------------------------------------------------------------------------
Variable |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
---------+--------------------------------------------------------------------
pre |      36    176.0278    6.529723    39.17834    162.7717    189.2838
post0 |      36    186.1944    7.826777    46.96066    170.3052    202.0836
---------+--------------------------------------------------------------------
diff |      36   -10.16667    5.433655    32.60193   -21.19757    .8642387
------------------------------------------------------------------------------
mean(diff) = mean(pre - post0)                               t =  -1.8711
Ho: mean(diff) = 0                              degrees of freedom =       35

Ha: mean(diff) < 0           Ha: mean(diff) != 0           Ha: mean(diff) > 0
Pr(T < t) = 0.0349         Pr(|T| > |t|) = 0.0697          Pr(T > t) = 0.9651

The t statistic is -1.8711 = (-10.1667-0) / 5.4337. The degrees of freedom is 35 = 36 – 1. The p-value of .0697 indicates a marginal significance but does not reject the null hypothesis at the .05 level. The treatment does not seem effective. The 95 percent confidence interval of the population mean is -10.16667 ± 2.03 * 5.433655, where 2.03 is the critical value of the .05 level and 35 degrees of freedom.

Alternatively, you may first compute the difference of each pair of the two variables, and then conduct the one-sample t-test. You may specify a hypothesized value other than zero in this approach.

. gen d=pre-post0
. ttest d=0
(output is skipped)

Top

3.2 Paired T-test in SAS

In the SAS TTEST procedure, you have to use the PAIRED statement instead of VAR. The following is the simple example of the PAIRED statement.

PROC TTEST DATA=masil.drug;
PAIRED pre*post0;
RUN;

The PAIRED statement provides various ways of comparing variables using asterisk (*) and colon (:) operators. The asterisk requests comparisons between each variable on the left with each variable on the right. The colon requests comparisons between the first variable on the left and the first on the right, the second on the left and the second on the right, and so forth. Consider the following examples.

PROC TTEST DATA=masil.drug;
PAIRED pro: post0;
PAIRED (a b)*(c d); /* Equivalent to PAIRED a*c a*d b*c b*d; */
PAIRED (a b):(c d); /* Equivalent to PAIRED a*c b*c; */
PAIRED (a1-a10)*(b1-b10);
RUN;

The first PAIRED statement is the same as PAIRED pre*post0. The second and the third PAIRED statements contrast differences between asterisk and colon operators. The hyphen (–) operator in the last statement indicates a1 through a10 and b1 through b10. Take a look at the following example of a paired t-test in SAS.

PROC TTEST H0=0 DATA=masil.drug;
PAIRED (pre)*(post0-post1)
RUN;
The TTEST Procedure

Statistics

Lower CL          Upper CL  Lower CL           Upper CL
Difference         N      Mean    Mean      Mean   Std Dev  Std Dev   Std Dev  Std Err

pre - post0       36     -21.2  -10.17    0.8642    26.443   32.602    42.527   5.4337
pre - post1       36    -30.43  -20.39    -10.34    24.077   29.685    38.723   4.9475

T-Tests

Difference         DF    t Value    Pr > |t|

pre - post0        35      -1.87      0.0697
pre - post1        35      -4.12      0.0002

The TTEST procedure presents descriptive statistics of the differences of paired observations. The small t statistic of -1.87 does not reject the null hypothesis of no difference between pre and post0 at the .05 significance level. However, -4.12 (= -20.39 / 4.9475) for the difference between pre and post1 rejects the null hypothesis and suggests a significant effect of the treatment (p<.0002).

In order to use the UNIVARIATE and MEANS procedures, the differences of matched pairs of two variables should be computed in advance.

DATA masil.drug2;
SET masil.drug;
d1 = pre - post0;
d2 = pre - post1;
RUN;

PROC UNIVARIATE MU0=0 VARDEF=DF NORMAL; VAR d1 d2; RUN;
PROC MEANS MEAN STD STDERR T PROBT CLM; VAR d1 d2; RUN;
PROC TTEST ALPHA=.05; VAR d1 d2; RUN;
(output is skipped)

Top

3.3 Paired T-test in SPSS

In SPSS, you need to list paired variables in the PAIRS subcommand. You may click Analyze--> Compare Means--> Paired-Samples T Test and then provide paired variables to be compared.

T-TEST
PAIRS = pre post0
/CRITERIA = CI(.95)