BookmarkSubscribeRSS Feed
stats_novice_44
Calcite | Level 5

Hey Everyone!

 

New SAS user here and I'm hoping you can help me solve a problem. In brief, I have a dataset where I need to compare the mean weight of two species of mouse. Moreover, I'm not simply testing whether or not they're different but rather, does the difference of their mean weight exceed 7 grams? Symbolically, my hypotheses may be stated as:

Ho: |µ1 - µ2| ≤ 7 or µD ≤ 7

Ha: |µ1 - µ2| > 7 or µD > 7

 

My question is, how do I translate this into SAS code? I found some documentation about the H0 option in proc ttest but I'm unsure about whether I've implemented it correctly for a two-sided test and I'm definitely unsure on how to ask a 1-sided question.

 

At present my code looks something like:

 

 

data weight;
input species_1 species_2;
cards;
22 36
18 24
23 34
22 24
14 37
15 34
;
run;

data weight2;
set weight;
weight = species_1;
species = 1;
output;
weight = species_2;
species = 2;
output;
drop species_1 species_2;
run;

proc sort data=weight2;
by species;
run;

proc ttest data=weight2 H0 = 7;
class species;
var weight;
run;

Any advice you all can offer would be much appreciated!

 

Thank you in advance!

8 REPLIES 8
Reeza
Super User
You're missing the SIDES option from the PROC TTEST statement to tell SAS it's a one sided test.

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=statug&docsetTarget=statu...

SIDE=2 | L | U
specifies the number of sides (or tails) and direction of the statistical tests and test-based confidence intervals. The values are interpreted as follows:

2
specifies two-sided tests and confidence intervals.

L
specifies lower one-sided tests (in which the alternative hypothesis indicates a parameter value less than the null value) and lower one-sided confidence intervals between minus infinity and the upper confidence limit.

U
specifies upper one-sided tests (in which the alternative hypothesis indicates a parameter value greater than the null value) and upper one-sided confidence intervals between the lower confidence limit and infinity.

By default, SIDES=2.
stats_novice_44
Calcite | Level 5

Hey, thank you for the quick reply! Seems like SIDES should do the trick but I do still have one concern.

My hypotheses concern the absolute difference between groups. The sample of my data above yields a mean difference of -12.5 if the default is µ1 - µ2 is used. If µ2-µ1 is used, this flips and becomes 12.5. How do I account for my case where I'm seeking to look at the absolute difference?

 

I just tried an alternative method. Does this look like it should adequately address my hypothesis?

 

data weight;
input species_1 species_2;
cards;
22 36
18 24
23 34
22 24
14 37
15 34
;
run;

data weight2;
set weight;
weight = species_1;
species = 1;
output;
weight = species_2;
species = 2;
output;
drop species_1 species_2;
run;

data weight_diff;
	set weight;
	weight_diff = abs(species_1 - species_2);
run;

proc ttest data=weight_diff H0 = 7 SIDES=U;
	var weight_diff;
run;
Reeza
Super User

@stats_novice_44 wrote:

My hypotheses concern the absolute difference between groups. 


Then that doesn't sound like a one sided test to me.

stats_novice_44
Calcite | Level 5

Well it's one-sided in that I'm trying to determine if the difference between means exceeds my value of interest, in this case 7.

 

Does |µ1 - µ2| exceed 7?

Reeza
Super User
Remove the absolute values signs and that becomes:

-7<= U1-U2 <=7

Which is a two sided test.

stats_novice_44
Calcite | Level 5
Ah, that makes sense. If I construct a new variable of the absolute differences as I did above, it should be one-sided though, correct?

Conversely, how would I set it up to do a two sided test where the differences fall between -7 and 7? Is my original code then sufficient?
StatDave
SAS Super FREQ

From your interest in the differences, I assume that your data is paired data, and your hypothesis sounds like an equivalence sort of test is desired. You probably need to use the TOST option in the PROC TTEST statement and the PAIRED statement with your original data arrangement with two response variables. See the example titled "Equivalence Testing with Lognormal Data" in the TTEST documentation - it involved lognormal data, but that is not required.

SteveDenham
Jade | Level 19

If you think of this as a non-inferiority test, I think the following may be of interest:

 

proc ttest data=weight2 h0=-7 sides=L;
class species;
var weight;
run;

This uses your 'long' dataset.  The output shows that the difference is significantly less than -7.

 

SteveDenham

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 8 replies
  • 3747 views
  • 7 likes
  • 4 in conversation