Programming the statistical procedures from SAS

Scott-Knott Multiple Comparison ... Is there any procedure in SAS??

Reply
Frequent Contributor
Posts: 103

Scott-Knott Multiple Comparison ... Is there any procedure in SAS??

Good day my SAS friends:

Always is a pleasure to participate here, so here we go one more time.

I'm working in some research and many authors located in a especial region of Brasil, use to be comfortable using  SCOTT-KNOTT Multiple Comparison, so

I always use the other and classic procedures (Tukey, Duncan, ETC).

Could anyone tell me please!!! how to get SCOTT-KNOTT multiple comparison in SAS.

Thanks.

King regard from Brasil

Valued Guide
Posts: 2,108

Re: Scott-Knott Multiple Comparison ... Is there any procedure in SAS??

Jonatan,

I can't, though I found lots of reference to R packages.

I found it fascinating that the only people publishing papers that use it are from Brazil.  I imagine that there is one 'enthusiast' who has converted the rest!

Doc Muhlbaier

Duke

Valued Guide
Valued Guide
Posts: 679

Re: Scott-Knott Multiple Comparison ... Is there any procedure in SAS??

I am not aware of a sas macro. I wrote a FORTRAN program to do this more than 30 years ago, and used it for a few years. I know it has the intuitive advantage of 'creating' non-overlapping groups of LSMEANS, based on the means and standard errors. Basically, it is a type of cluster analysis (of means). However, early assessments showed that the experiment-wise Type I error rate can be high with this method. This would likely be the reason why the method is very uncommon, and not available within SAS procedures. I have not read anything about it in decades, so there may be some counter-arguments to the criticisms. Someone who has the time and knows PROC IML could probably take one of the multiple-comparison macros that have been written by non-SAS programmers, and add a routine for this method. I would start with the macro written by H.P. Piepho.

http://agrobiol.sggw.waw.pl/~cbcs/articles/CBCS_7_1_2.pdf

This would take some expertise with IML, and time.

Or, you could call a relevant R function for SK from within SAS IML to do this. You would have to learn about the SAS-R linkages first.

Occasional Contributor
Posts: 8

Re: Scott-Knott Multiple Comparison ... Is there any procedure in SAS??

So, did you get some routine?

Valued Guide
Valued Guide
Posts: 679

Re: Scott-Knott Multiple Comparison ... Is there any procedure in SAS??

I haven't looked since I don't need it.

Frequent Contributor
Posts: 103

Re: Scott-Knott Multiple Comparison ... Is there any procedure in SAS??

hi there :

Unfortunately still don't have it :/ , such a bad luck hum?

i think the person deveplops this method for SAS will be very famous

Respected Advisor
Posts: 2,655

Re: Scott-Knott Multiple Comparison ... Is there any procedure in SAS??

Why? As @lvm said, the experiment wise type I error with this method is high, and there are much better methods for controlling for this sort of error already available using the ADJUST= option in the linear models procedure, and in PROC MULTTEST.

Steve Denham

Frequent Contributor
Posts: 103

Re: Scott-Knott Multiple Comparison ... Is there any procedure in SAS??

Hi SteveDenham:

For sure, this is the objective to be tested, could you send us an example using these methodologies.

thanks

Respected Advisor
Posts: 2,655

Re: Scott-Knott Multiple Comparison ... Is there any procedure in SAS??

Start here in the documentation:

https://support.sas.com/documentation/cdl/en/statug/68162/HTML/default/viewer.htm#statug_mixed_synta...

See also the Shared Concepts for LSMEANS and the documentation for PROC MULTTEST.

Steve Denham

N/A
Posts: 1

Re: Scott-Knott Multiple Comparison ... Is there any procedure in SAS??

Fiz uma busca ampla sobre a existência de tal rotina no SAS, no entanto, nada encontrei. Não sei qual as limitações de uso, mas sei que essa rotina está disponível no R e em um software livre chamado ASSISTAT. No entanto leve em consideração que esse teste não é propriamente para comparações de médias e sim um teste de agrupamentos a partir uma única variável, apresentando limitações teóricas como já descritas acima.

Frequent Contributor
Posts: 103

Re: Scott-Knott Multiple Comparison ... Is there any procedure in SAS??

Ola Luis Carlos:

obrigado pela tua resposta, nesse sentido voce tem como me informar onde tem aquela rotina de R por favor??

desde ja agradeço tua resposta

abç

Occasional Contributor
Posts: 8

Re: Scott-Knott Multiple Comparison ... Is there any procedure in SAS??

/*Scott-Knott in R and SAS (integration*/

*;

/*Tutorial by: (Alysson Jalles) Consultoria: www.alyssonjallessite.wordpress.com*/

*;

*I have the solution;

*I've wrote a R/SAS routine for this purpose;

*You can run R inside SAS to do it!;

*To set SAS to run R codes follow my tutorial in: https://communities.sas.com/message/296841#296841;

*Copy all of this message inside SAS to perform the analysis;

*;

*I'll provide an example with a SAS simulated dataset of a Randomized Complete Block Design (RCBD);

*;

*;

*=======================================================================;

*Simulating a RCBD experiment ===========================================BEGIN;

*=======================================================================;

*10 TREATMENTS;

*3 REPLICATION;

proc plan seed=123456;

factors GEN=10 ordered REP=3 ordered/noprint;

output out=RCBD_TEST

/*GEN cvals=('GEN1' 'GEN2' 'GEN3' 'GEN4' 'GEN5' 'GEN6' 'GEN7' 'GEN8' 'GEN9' 'GEN10')*/

GEN nvals=(1 2 3 4 5 6 7 8 9 10)

REP nvals=(1 2 3);

run;

*;

*Simulating VARIABLES - BEGIN;

data RCBD_TEST; set RCBD_TEST;

  call streaminit(8789); /*SEED= 8789*/

VAR1=rand('normal',110, 15); /*MEAN 110: STD: 15*/

run;

data RCBD_TEST; set RCBD_TEST;

  call streaminit(907854); /*SEED= 907854*/

VAR2=rand('normal',3000, 751);run; /*MEAN 3000: STD: 751*/

*Simulating VARIABLES - END;

*=======================================================================;

*Simulating and RCBD experiment =====================================END;

*=======================================================================;

*;

*Printing dataset, first 6 observations of simulated dataset:;

proc print data=RCBD_TEST (obs=6); run;

*;

*;

/*Scott-Knott statistic of VAR1 and VAR2 in R language*/

*Installing "ScottKnott" package in R;

*ScottKnott in an R package to perform Scott-Knott analysis;

*It will appear a windows, just click on the nearest mirror of your current place;

* You just need to do it ONCE!;

proc iml;

title "Installing ScottKnott package in R (integration R with SAS)";

submit / R;

#_______Begin of R code_________________

install.packages("ScottKnott")

#_______End of R code_________________

endsubmit;

*quit;

*;

*;

*Installing "xlsx" package in R;

*xlsx is a package to export Scott-Knott results in excel to your hard drive;

*to use this package you have to install the ultimate version of java in your computer:

https://www.java.com/pt_BR/download/

*It will appear a windows, just click on the nearest mirror of your current place;

* You just need to do it ONCE!;

proc iml;

title "Installing xlsx package in R (integration R with SAS)";

submit/ R;

#_______Begin of R code_________________

  install.packages("xlsx")

#_______End of R code_________________

endsubmit;

*quit;

*;

*;

*****SCOTT-KNOTT ANALYSIS BEGINS HERE..*******************************************************;

*Changing treatments - GEN from numeric to factor type;

*This is necessary;

proc iml;

title "Preparing variables (integration R with SAS)";

*Exporting SAS dataset to R environment;

run ExportDataSetToR("WORK.RCBD_TEST", "RCBD_IN_R");

submit / R;

#_______Begin of R code_________________

#Class of GEN and REP

class(RCBD_IN_R$GEN)

class(RCBD_IN_R$REP)

#CONVERTING "GEN" and "REP" TO CHARACTER

RCBD_IN_R$GEN<-as.character(RCBD_IN_R$GEN)

RCBD_IN_R$REP<-as.character(RCBD_IN_R$REP)

#Class of GEN and REP

class(RCBD_IN_R$GEN)

class(RCBD_IN_R$REP)

#_______End of R code_________________

endsubmit;

*quit;

*;

*;

*;

*Performing the Scott-Knott analysis;

*We'll perform the analysis with 2 VARIABLES simultaneously, but you can extend this routine to N variables;

title "Performing ScottKnott clustering in R (integration R with SAS) - by: Alysson Jalles";

submit / R;

#_______Begin of R code_________________

require(ScottKnott) #Package to perform the SK analysis

require(xlsx)          #Package to perform the output in XLSX of results

#For other kind of design as CRD, factorial, etc, consult the manual of R ScottKnott package

#in: https://cran.r-project.org/web/packages/ScottKnott/ScottKnott.pdf

#Applying univariate Scott-Knott clustering

VAR1a <- SK(x=RCBD_IN_R, y=RCBD_IN_R$VAR1, model="y~GEN+REP", which="GEN", sig.level=0.05)

#summary(VAR1a)

VAR2a <- SK(x=RCBD_IN_R, y=RCBD_IN_R$VAR2, model="y~GEN+REP", which="GEN", sig.level=0.05)

#summary(VAR2a)

#Summary

VAR1b<-(summary(VAR1a))

VAR2b<-(summary(VAR2a))

#_____________________________

#RENAMING MEANS TO THE NAME OF VARIABLE EVALUATED

names(VAR1b)[names(VAR1b)=="Means"] <- "VAR1"

names(VAR2b)[names(VAR2b)=="Means"] <- "VAR2"

#RENAMING SK(5%)TO SK PLUS NAME OF VARIABLE EVALUATED

names(VAR1b)[names(VAR1b)=="SK(5%)"] <- "SK_VAR1"

names(VAR2b)[names(VAR2b)=="SK(5%)"] <- "SK_VAR2"

#MERGING SCOTT-KNOTT RESULTS IN A SINGLE DATASET

SK <-Reduce(function(x, y) merge(x, y, all=TRUE),

            list(

  VAR1b,  #VAR1

  VAR2b  #VAR2

  ))

#RENAMING NAME OF VAR "Levels" TO GEN [TREATMENTS]

names(SK)[names(SK)=="Levels"] <- "GEN"

#_______End of R code_________________

endsubmit;

*quit;

*;

*;

*Exporting R results to your hard drive and SAS Environment;

title "Exporting results to Windows hard drive and SAS Environment (integration R with SAS)";

title2 "Your file: 'Scott_Knott_output.xlsx' is in C:\ of your HD";

*Exporting results from R to SAS;

run importdatasetfromR("WORK.SCOTT_KNOTT_SAS","SK");

submit / R;

#_______Begin of R code_________________

write.xlsx(SK, "Scott_Knott_output.xlsx")

#_______End of R code_________________

endsubmit;

*quit;

*;

*;

*Sorting treatments - GEN;

proc sort; by GEN; run;

*;

*;

*Printing results of Scott-Knott analysis in SAS (sig.level=0.05);

Title "Scott-Knott Analysis results to RCBD design in SAS, by: Alysson Jalles";

proc print data=SCOTT_KNOTT_SAS noobs; run;


*****SCOTT-KNOTT ANALYSIS ENDS HERE..*******************************************************;

Thanks for read my material :smileygrin:...

Frequent Contributor
Posts: 103

Re: Scott-Knott Multiple Comparison ... Is there any procedure in SAS??

Thank you for your contribution.

 

we'll test and compare this protocol and them we'll leave you any comment. Untill now we appreciate this.

 

Thank you

Frequent Contributor
Posts: 103

Re: Scott-Knott Multiple Comparison ... Is there any procedure in SAS??

Good day my friend:

 

As you know, ths SAS university edition is improveing each day, so i tried to use iyour code in SAS university edition and i could not finish the statement.

 

Anybody caould help with this???

 

Thank you

Occasional Contributor
Posts: 8

Re: Scott-Knott Multiple Comparison ... Is there any procedure in SAS??

Hi jonatan_velarde..the bad news is that SAS university edition does not run any R codeCat Indifferent

If you want to run this routine you should have the Commercial SAS version.

Or by other hand, you can run the second part of the routine totally in R or RStudio.

 

 

#####################################################################################

#(English titleSmiley HappyScott-Knott univariate clustering in R to RCBD.
#(Portuguese-Br title): Agrupamento univariado de Scott-Knott para DBC)
#routine By Alysson Jalles.
#www.alyssonjallessite.wordpress.com

#Here we have 2 variables to evaluate.
#Creating a dataset with RCBD data...
RCBD_IN_R<-read.table(header=TRUE, text=("
GEN REP VAR1 VAR2
1 1 109.797 4296.39
1 2 109.325 3159.55
1 3 129.079 2550.13
2 1 124.041 3206.70
2 2 102.700 3498.19
2 3 90.762 2676.06
3 1 127.014 3287.07
3 2 127.461 2345.28
3 3 122.337 3649.71
4 1 95.214 2339.48
4 2 106.913 2118.81
4 3 107.182 2426.04
5 1 119.641 3811.88
5 2 94.830 4166.51
5 3 124.218 2457.73
6 1 110.261 2276.99
6 2 106.819 1494.28
6 3 103.399 1452.75
7 1 123.564 740.09
7 2 109.369 1561.06
7 3 122.680 1951.73
8 1 103.247 3259.35
8 2 103.542 3363.61
8 3 109.542 3149.99
9 1 113.026 1924.95
9 2 76.786 3041.53
9 3 91.773 1807.83
10 1 81.236 3458.72
10 2 95.125 3185.58
10 3 95.898 3039.91
                    "))

#Changing treatments - GEN from numeric to character type;
#Class of GEN and REP
class(RCBD_IN_R$GEN)
class(RCBD_IN_R$REP)
#CONVERTING "GEN" and "REP" TO CHARACTER
RCBD_IN_R$GEN<-as.character(RCBD_IN_R$GEN)
RCBD_IN_R$REP<-as.character(RCBD_IN_R$REP)
#Class of GEN and REP
class(RCBD_IN_R$GEN)
class(RCBD_IN_R$REP)

#Intalling packages to Analysis.
  #Scott-Knott statistic of VAR1 and VAR2 in R language*/
  #Installing "ScottKnott" package in R;
  #ScottKnott in an R package to perform Scott-Knott analysis;
  #It will appear a windows, just click on the nearest mirror of your current place;
  #You just need to do it ONCE!;
install.packages("ScottKnott") #To Performa SK analysis

#Installing "xlsx" package in R;
  #xlsx is a package to export Scott-Knott results in excel to your hard drive;
  #to use this package you have to install the ultimate version of java in your computer:
  #https://www.java.com/pt_BR/download/
  #When you click in install.packages("xlsx") It will appear a windows,
  #just click on the nearest mirror of your current place;
  #You just need to do it ONCE!;
install.packages("xlsx")       #Package to export your dataset to excel

#Performing the Scott-Knott analysis;
  #We'll perform the analysis with 2 VARIABLES simultaneously,
  #but you can extend this routine to N variables;
  #_______Begin of R code_________________
require(ScottKnott) #Package to perform the SK analysis
require(xlsx)          #Package to perform the output in XLSX of results
  #For other kind of design as CRD, factorial, etc, consult the manual of R ScottKnott package
  #in: https://cran.r-project.org/web/packages/ScottKnott/ScottKnott.pdf
  #Applying univariate Scott-Knott clustering
VAR1a <- SK(x=RCBD_IN_R, y=RCBD_IN_R$VAR1, model="y~GEN+REP", which="GEN", sig.level=0.05)
#summary(VAR1a)
VAR2a <- SK(x=RCBD_IN_R, y=RCBD_IN_R$VAR2, model="y~GEN+REP", which="GEN", sig.level=0.05)
#summary(VAR2a)
#Summary
VAR1b<-(summary(VAR1a))
VAR2b<-(summary(VAR2a))
#_____________________________
#RENAMING MEANS TO THE NAME OF VARIABLE EVALUATED
names(VAR1b)[names(VAR1b)=="Means"] <- "VAR1"
names(VAR2b)[names(VAR2b)=="Means"] <- "VAR2"
#RENAMING SK(5%)TO SK PLUS NAME OF VARIABLE EVALUATED
names(VAR1b)[names(VAR1b)=="SK(5%)"] <- "SK_VAR1"
names(VAR2b)[names(VAR2b)=="SK(5%)"] <- "SK_VAR2"
#MERGING SCOTT-KNOTT RESULTS IN A SINGLE DATASET
SK <-Reduce(function(x, y) merge(x, y, all=TRUE),
            list(
              VAR1b,  #VAR1
              VAR2b  #VAR2
            ))
#RENAMING NAME OF VAR "Levels" TO GEN [TREATMENTS]
names(SK)[names(SK)=="Levels"] <- "GEN"
#_______End of R code_________________


#Exporting R results to your hard drive and SAS Environment;
#"Your file: 'Scott_Knott_output.xlsx' is in C:\ of your HD";
#Exporting results from R to SAS;
#_______Begin of R code_________________
setwd("C:/") #Assigning path to output file
getwd()       #Checking out if your file was exported sucessfully
write.xlsx(SK, "Scott_Knott_output.xlsx")
View(SK) #Once you View your table in RStudio you can copy and paste your results in excel.
#_______End of R code_________________

 

 
Ask a Question
Discussion stats
  • 14 replies
  • 1801 views
  • 1 like
  • 6 in conversation