Solved
Contributor
Posts: 58

The Single-Factor Within-Subjects Design

Hi SAS Community,

I am analyzing a single factor within subject design dataset where

1. subjects were measured at baseline and follow-up (2 time points only). Here is a small subset of the data, where test is 1=baseline and 2=follow-up.

data within_subject;

input id test outcome;

datalines;

1 1 3

1 2 2

2 1 4

2 2 3

3 1 9

3 2 7

4 1 4

4 2 2

5 1 1

5 2 0.5

;

run;

I used proc mixed to test for baseline to post difference (syntax show below)

proc mixed data=within_subject;

class test;

model outcome=test;

repeated /subject=id type=ar(1);

lsmeans test;

run;

Since this data has only 2 time points, my understanding is that I will get the same result by using a paired t-test. Of course for paired t-test I will need to structure my data as a wide datafile instead of a person-time datafile as shown below:

data t_test;

input id test1 test2;

datalines;

1 3 2

2 4 3

3 9 7

4 4 2

5 1 0.5

;

run;

The paired t-test code is shown below:

proc ttest data=t_test;

paired test1*test2;

run;

I got the same result using both codes but just wanted to confirm with the SAS experts that both approach have the same correlation structure.

Best,

Pronabesh

Accepted Solutions
Solution
‎03-21-2014 09:35 AM
Posts: 2,655

Re: The Single-Factor Within-Subjects Design

Yes, you should get the same.  You could use type=un in proc mixed if you want unequal variances and a covariance for the pre and post.  It doesn't matter in proc ttest, as the variable that is actually fit is the difference, and the assumptions all fall on the difference.

Steve Denham

All Replies
Solution
‎03-21-2014 09:35 AM
Posts: 2,655

Re: The Single-Factor Within-Subjects Design

Yes, you should get the same.  You could use type=un in proc mixed if you want unequal variances and a covariance for the pre and post.  It doesn't matter in proc ttest, as the variable that is actually fit is the difference, and the assumptions all fall on the difference.

Steve Denham

Contributor
Posts: 58

Re: The Single-Factor Within-Subjects Design

Thank you for confirming that Steve. I got the same results using unstructured and first order auto-regressive. Is it correct to assume that with 2 time points ar(1) has the same correlation structure as un?

As always, that you so much for your help.

Best,

Pronabesh

Posts: 2,655

Re: The Single-Factor Within-Subjects Design

With two time points, and no other factors, either random or fixed, un and ar(1) will give the same results.  Note that the entries in the matrix may not be the same, but the two matrices are congruent (I think that is the correct word for matrices that are the same except for a scalar factor).

Steve Denham

🔒 This topic is solved and locked.