turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Analytics
- /
- Stat Procs
- /
- How do I set up contrasts in npar1way?

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-16-2017 03:35 AM

I have a data set consisting of 4 independent samples: W_C, W_T, M_C, M_T. I wish to test the difference (W_C - W_T) - (M_C - M_T). Normally I would do a two-way ANOVA and look at the interaction term, but my samples sizes are very small.

I thought of Kruskal-Wallis in npar1way with *apriori* contrasts of the form

1 -1 -1 1

but I can't seem to find any way to set this up.

My experience with SAS (long but limited) has taught me that it can do just about anything, and do it well, if you can figure out how.

Can anybody help (SAS University Edition 9.4)?

Accepted Solutions

Solution

a month ago

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

a month ago

You ask good questions, and unfortunately I don't have all the answers.

> I would very much like your opinion on the npar1way>multtest combination.

My opinion is that you should ask someone who knows more about those procedures than I do. :-)

> something is wrong with the code you suggest. I ran the data using QuantReg and then with npar1way followed by multtest.

> The results were very very different: a p-value of 0.0542 from QuantReg vs a p-value of 0.0075 from multtest

Let me just say that these procedures are using different statistics and running different tests. For this very small data set (14 obs, joint levels have between 2 and 5 obs), the standard errors that PROC QUANTREG produces are larger than you are getting from your other method. If you are happy with the other method and its assumptions, feel free to accept its conclusion.

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-16-2017 11:22 AM

Not sure if the following exactly matches what you are trying to do, but I think it may come close: https://communities.sas.com/t5/SAS-Procedures/proc-npar1way-contrasts-statement/td-p/265531

Art, CEO, AnalystFinder.com

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-17-2017 02:47 AM

Dear Art,

Thank you for your quick reply.

Actually, before posting, I did a search of the forum and came up with the exchange you refer me to. Unfortunately, the solution there is for multiple pairwise comparisons whereas I require a difference of a difference. I couldn't (and still can't) see how to get from the one to the other—can you?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-17-2017 09:34 AM

Since you have a small data, why not try EXACT statement of PROC NPAR1WAY or PROC FREQ ?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-17-2017 11:37 AM

Dear Ksharp,

Thank you for your quick reply.

I do use EXACT in Npar1way but can only figure out how to test all 4 samples using Kruskal-Wallis or how to compare various pairs using a BY variable; I would be very grateful if you could be more specific on how to test the difference of a difference: (D-C) - (B-A).

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

a month ago

Sorry. I am not expert about it. I would leave it to @SteveDenham @lvm @Rick_SAS

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

a month ago

Can I turn to them directly or do I have to wait (and hope) that one of them will chance by?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

a month ago

When someone is mentioned by name in a post, they receive a notification. It is a breach of etiquette to explicitly contact someone you don't know for help. Be patient: if someone has the knowledge and the time, they will offer a suggestion.

If you provide a reference and sample data, you are more likely to get a response

I don't know how to do what you ask. You might need to transform your data from wide to long and use two group variables to encode the data, like this

CLASS Group1 Group2;

VAR Value;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

a month ago

Dear Rick,

Thank you, now I know.

It is evening here and I can answer properly only tomorrow. In the meanwhile, I have a couple of preliminary questions.

What do you mean by 'provide a reference'?

My data is in an Excel file (14 lines); would it be alright just to copy it (together with the sas program that reads it and the npar1way code) so the reader can get the idea, or should I convert it to an actual SAS data statement?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

a month ago - last edited a month ago

**> provide a reference**

A reference is a book, article, or web site where the reader can go to learn more about the question you are asking. For example:

"I want to run the SuperCool Test from Jones and Smith's 1999 textbook "Cool Statistical Tests" (2nd ed, p 129)"

or

"At the web site www.SuperCoolTest.net they show how to conduct the SuperCool Test in [STATA, MATLAB, R, SPSS, PYTHON,...].

or

"The example in the SAS documentation [LINK] shows how to do the SuperCool analysis. However, my data has missing values and I get the following error: ..."

**> how to supply data**

Data on the forums should be supplied in the form of a SAS DATA step. Some people object to downloading Office files because of a perceived security risk. You can use PROC IMPORT to create a SAS data set, then use a macro program to generate a SAS DATA step. You can also use any of the 200 SASHELP data sets, which are distributed with SAS . For example, SASHELP.Cars, SASHELP.Class, SASHELP.Iris, SASHELP.BWeight, etc,

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

a month ago

Oh, those kinds of references. I know all about them, I'm a scientist. I thought it was something specific to SAS.

I'll be back tomorrow, with a full (short, but functioning) sas program and a little of the science behind it.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

a month ago

The purpose of the experiment is to determine whether a particular drug (the treatment T) has a greater effect in genetically modified mice (Mut) than in normal mice (Wild-Type).

Four independent groups of mice are selected: normal untreated (WT_C), normal with drug (WT_T), mutants untreated (Mut_C), and mutants with drug (Mut_T). The variable under study is a particular parameter of cardiac function we will label 'X'.

It is well-known from the literature that T decreases X in WT mice. There is less evidence for this mutant strain, but here too T appears to decrease X. When X is (more or less) normally distributed and sample sizes are adequate, we would use a two-way ANOVA

treatment

no yes

wild-type WT_C WT_T

genome

mutant Mut_C Mut_T

and test the interaction term: genome x treatment.

But the experiment is long and difficult and costly, and our entire sample size is only 14. So we have no choice but to use an exact nonparametric test, and I thought of npar1way with apriori contrasts of the form

1 -1 -1 1

but I can find no way to set this up, basically (WT_C - WT_T) - (Mut_C - Mut_T).

The short sas program below produces two exact Mann-Whitney tests, WT_C versus WT_T and Mut_C versus Mut_T; without the 'by' statement, one gets the exact Kruskal-Wallis test for all 4 groups. The number of cases in each group is correct (3,5,2,4) but I have not used the original X values.

ODS RTF File ="/folders/myshortcuts/Norman/Ahmad/test-4.rtf" bodytitle;

data ahmad;

input G$ X W;

cards;

WT_C 25 1

WT_C 24 1

WT_C 23 1

WT_T 22 1

WT_T 21 1

WT_T 20 1

WT_T 19 1

WT_T 18 1

Mut_C 23 2

Mut_C 22 2

Mut_T 15 2

Mut_T 14 2

Mut_T 13 2

Mut_T 12 2

;

run;

proc npar1way data=ahmad plots=none wilcoxon;

class G;

by W;

exact wilcoxon;

var X;

run;

ODS RTF close;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

a month ago

I do not know how to do this analysis in NPAR1WAY; perhaps @PGStats might have an idea.

I will throw out an alternative suggestion: use QUANTREG, which has an ESTIMATE statement. The background/rationale for my suggestion is given in the article "Quantile estimates and the difference of medians in SAS." The estimate you are looking for is given below (I think, please double check my ESTIMATE statement, which is different from the one you suggested). Note that I changed the class levels to better reflect the two class variables.

```
data Have;
length G $3. W $1. Group $5.;
input G X W;
Group = cats(G, '_', put(W,1.)); /* create group variable that combines the 4 levels */
datalines;
WT 25 C
WT 24 C
WT 23 C
WT 22 T
WT 21 T
WT 20 T
WT 19 T
WT 18 T
Mut 23 C
Mut 22 C
Mut 15 T
Mut 14 T
Mut 13 T
Mut 12 T
;
proc quantreg data=Have;
class Group;
model X = Group / quantile=0.5;
estimate 'Difference of Differences' Group -1 1 1 -1 / CL;
run;
```

:

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

a month ago

I'll look into it tomorrow. What do you think of

proc multitest data=ahmad perm;

class G;

contrast 'delMut - delWT' -1 1 1 -1;

test mean (X);

run;

to follow proc npar1way (without the 'by' statement, of course), as suggested by Richter & Higgins (2006): "A SAS Companion for Nonparametric Statistics", Thomson Brooks/Cole, Belmont, CA, p.28?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

a month ago

Dear Rick,

Most of my (recent) SAS experience has been with version 9.1.3 and I was not familiar with QuantReg. I read the reference you gave and looked at the entry in the 9.4 manual. QuantReg would appear to be a very useful and versatile addition to my nonparametric arsenal, and I plan to devote more time to it when this project is over.

But something is wrong with the code you suggest, and I don't (yet) know the program well enough to uncover what that is. I ran the data using QuantReg and then with npar1way followed by multtest as described in the little book by Richter & Higgins I cited above—the results were very very different: a p-value of 0.0542 from QuantReg, a p-value of 0.0075 (raw) and 0.0095 (permutation) from multtest.

I then ran the Kruskal-Wallis routine implemented by NCSS (NCSS 10 Statistical Software (2015). NCSS, LLC. Kaysville, Utah) with custom contrasts; using 1 -1 -1 1, I got a p-value of 0.0075 here too.

So why, you might ask, do I bother with SAS when I can get what I want with NCSS? Well, not quite. The p-value of 0.0075 provided by NCSS is the asymptotic value, and I am (was) looking for an exact value. That was why I turned to SAS>npar1way and that, I believe, is what I have now found in multtest (permutation).

I would very much like your opinion on the npar1way>multtest combination.