macro

phkw  cssize inputcol

mcolumns cssize inputcol

mconstants what

note: This is a macro for Posthoc analysis after Kruskal-Wallis test either multigroup comparison or

note: comparison againt a single control .

note:  For computational details refer to

note: Nonparametric statistics for behavioural sciences

note: Siegel S and Castellan NJ, 2nd edition, 1988 , McGraw Hill, Inc, New York, page 213-215

note: PLEASE REMEMBER TO ENTER THE AVERAGE RANKS IN THE INPUT COLUMN

Note: What type of post hoc analysis you wish to perform

Note: Type YES & enter for multipgroup comparison.  Type NO & enter for single group comparison

yesno what

if what=1

call phkwmgc cssize inputcol

elseif what=0

call phkwsgc cssize inputcol

endif

call phlabels

endmacro

 

 

####MACRO FOR MULTI GROUP COMPARISON

macro

phkwmgc cssize inputcol

mcolumns inputcol nsrno ctemp1 ctemp2 ctemp3 cdummy srno dcola dcolb diffcol diffabs ccga ccgb work1 sig05 sig01

mcolumns cssa cssb cssize cwk1 cwk2 ccrit05 ccrit01

mconstants nperiods npminus1 nexttp nexttp1 kremain npplus1 ncomp ktemp1 nsample

mconstants a05 a01 z05 z01 wk1 wk2 crsdif05 crsdif01  kwk1 ktotrank

#Post hoc analysis after Friedman's test. REf: Nonparametric statistics for behavioural sciences

# Siegel S and Castellan NJ, 2nd edition, 1988, page 180 , McGraw Hill, Inc, New York,

 

 

 

let nsample=cssize(1)

let ktotrank=sum(cssize)

let nperiods=count(inputcol)

let ncomp=(nperiods*(nperiods-1))/2

 

let npminus1=nperiods-1

 

set srno

1:ncomp

end

set nsrno

1:nperiods

end

set ctemp1

0

end

#Creating comparable groups column i.e dcola

let nexttp=0

let nexttp1=0

let kremain=0

while nexttp<npminus1

let nexttp=nexttp+1

let nexttp1=nexttp+1

copy inputcol ctemp2;

use nexttp1:nperiods.

stack ctemp1 ctemp2 ctemp3

copy ctemp3 ctemp1

endwhile

copy ctemp3 ctemp3;

omit 1.

let dcola=ctemp3

#creating comparing groups column i.e dcolb

let nexttp=0

let nexttp1=0

let kremain=0

erase ctemp1 ctemp2 ctemp3

set ctemp1

0

end

while nexttp<npminus1

let nexttp=nexttp+1

let nexttp1=nexttp+1

let kremain=nperiods-nexttp

let ktemp1=inputcol(nexttp)

set ctemp2

1(ktemp1:ktemp1/1)kremain

end

stack ctemp1 ctemp2 ctemp3

copy ctemp3 ctemp1

endwhile

copy ctemp3 ctemp3;

omit 1.

let dcolb=ctemp3

 

#Creating comparable groups number column i.e ccga

let nexttp=0

let nexttp1=0

let kremain=0

erase ctemp1 ctemp2 ctemp3

set ctemp1

0

while nexttp<npminus1

let nexttp=nexttp+1

let nexttp1=nexttp+1

copy nsrno ctemp2;

use nexttp1:nperiods.

stack ctemp1 ctemp2 ctemp3

copy ctemp3 ctemp1

endwhile

copy ctemp3 ctemp3;

omit 1.

let ccga=ctemp3

#creating comparing groups number column i.e ccgb

let nexttp=0

let nexttp1=0

let kremain=0

erase ctemp1 ctemp2 ctemp3

set ctemp1

0

end

while nexttp<npminus1

let nexttp=nexttp+1

let nexttp1=nexttp+1

let kremain=nperiods-nexttp

let ktemp1=nsrno(nexttp)

set ctemp2

1(ktemp1:ktemp1/1)kremain

end

stack ctemp1 ctemp2 ctemp3

copy ctemp3 ctemp1

endwhile

copy ctemp3 ctemp3;

omit 1.

let ccgb=ctemp3

#Creating comparable groups samle size column i.e cssa

let nexttp=0

let nexttp1=0

let kremain=0

erase ctemp1 ctemp2 ctemp3

set ctemp1

0

while nexttp<npminus1

let nexttp=nexttp+1

let nexttp1=nexttp+1

copy cssize ctemp2;

use nexttp1:nperiods.

stack ctemp1 ctemp2 ctemp3

copy ctemp3 ctemp1

endwhile

copy ctemp3 ctemp3;

omit 1.

let cssa=ctemp3

#creating comparing groups samle size  column i.e cssb

let nexttp=0

let nexttp1=0

let kremain=0

erase ctemp1 ctemp2 ctemp3

set ctemp1

0

end

while nexttp<npminus1

let nexttp=nexttp+1

let nexttp1=nexttp+1

let kremain=nperiods-nexttp

let ktemp1=cssize(nexttp)

set ctemp2

1(ktemp1:ktemp1/1)kremain

end

stack ctemp1 ctemp2 ctemp3

copy ctemp3 ctemp1

endwhile

copy ctemp3 ctemp3;

omit 1.

let cssb=ctemp3

#calculating the z value for 0.05 significance and 0.01 signifiance

let a05=0.05/(ncomp*2)

let a01=0.01/(ncomp*2)

InvCDF a05 z05;

Normal 0.0 1.0.

InvCDF a01 z01;

Normal 0.0 1.0.

let z05=absolute(z05)

let z01=absolute(z01)

#Caculating the critical value for significant difference at 0.05 and 0.01; cwk1 cwk2  constant columns for critical value

 

let kwk1=((ktotrank*(ktotrank+1)/12))

let cwk1=((1/cssb)+(1/cssa))

let cwk2=(kwk1*cwk1)**0.5

let ccrit05=cwk2*z05

let ccrit01=cwk2*z01

#### calculating the difference and determining whether the difference is significant at 0.05, 0.01 level

let diffcol=dcola-dcolb

let diffabs=absolute(diffcol)

let sig05=diffabs>ccrit05

let sig01=diffabs>ccrit01

 

print inputcol ccgb ccga dcolb dcola  diffcol sig05 sig01

 

endmacro

####

macro

phlabels

note: Description of columns : Input column i.e Average ranks

note: nsrno=Group serial number; ccgb=base group; ccga=comparative group

note: dcolb=Average rank of base group; dcola=Average rank of comparative group

note: diffcol=Difference in Average ranks

note: sig05= 1 implies significance at 0.05 level and 0 implies not signficant

note: sig01= 1 implies significance at 0.01 level and 0 implies not signficant

endmacro

##########MACRO FOR SINGLE GROUP COMPARISON

MACRO

phkwsgc cssize inputcol

mcolumns inputcol work1 work2 sscol tempic tempic2 diffcol srno dcola dcolb diffabs sig05 sig01 

mcolumns qsrno q05 q01 ccga ccgb nsrno cssa cssb cssize cwk1 cwk2 ccrit05 ccrit01 cssdummy

 

mconstants nsample nperiods ncomp cv05 cv01 a05 a01 z05 z01 crsdif05 crsdif01 ktmpsize ktotrank kremain

mconstants nextval tempdiff nexttp tempk1 tempk2 nvplus2 npminus1 nexttp1 kwk1

mconstants compgrp contval contsize kssmean kssstru

#Test for the number of periods for comparison

let nperiods=count(inputcol)

 

 

#Post hoc analysis after Friedman's test. REf: Nonparametric statistics for behavioural sciences

# Siegel S and Castellan NJ, 2nd edition, 1988 , McGraw Hill, Inc, New York,page 213

note: What is the comparative group. Enter the number 1 or 2 or 3 etc and press enter key

set work2;

file 'terminal';

nobs 1.

 

let nextval=1

let nexttp=0

 

let ktotrank=sum(cssize)

let nextval=1

let nexttp=0

 

let nsample=cssize(1)

 

let ncomp=nperiods-1

let npminus1=nperiods-1

let compgrp=work2(1)

let contval=inputcol(compgrp)

let contsize=cssize(compgrp)

let kssmean=mean(cssize)

set srno

1:ncomp

end

let npminus1=nperiods-1

 

#PLEASE NOTE FORMULA FOR NCOMP IN SINGLEGROUP COMPARISON UNLIKE MULTIGROUP COMPARISION

let ncomp=nperiods-1

let npminus1=nperiods-1

 

 

set srno

1:ncomp

end

set nsrno

1:nperiods

end

set qsrno

1:20

end

set q05

1.96

2.21

2.35

2.44

2.51

2.57

2.61

2.65

2.69

2.72

2.74

2.77

2.79

2.81

2.83

2.846

2.862

2.878

2.894

2.910

end

set q01

2.58

2.79

2.92

3.0

3.06

3.11

3.15

3.19

3.22

3.25

3.27

3.29

3.31

3.33

3.35

3.364

3.378

3.392

3.406

3.420

end

#Creating different columns for calculation of crtical value for significant difference

copy inputcol dcola;

omit compgrp.

set dcolb

1(contval:contval/1)npminus1

end

set cssb

1(contsize:contsize/1)ncomp

end

copy cssize cssa;

omit compgrp.

set ccgb

1(compgrp:compgrp/1)ncomp

end

copy nsrno ccga;

omit compgrp.

####Determining whether  sample sizes all groups is same : See page 215 of the reference

while nexttp<nperiods

let nexttp=nexttp+1

let cssdummy(nexttp)=cssize(nexttp)=kssmean

endwhile

let kssstru=sum(cssdummy)=nperiods

 

#calculating the z value for 0.05 significance and 0.01 signifiance

# If the sample size in all groups is same and number of groups for comparison is less than 21, then above

#table could be used.  Else z values based on normal distribution could be used

if kssstru and nperiods le 21

let z05=q05(ncomp)

let z01=q01(ncomp)

else

let a05=0.05/(ncomp*2)

let a01=0.01/(ncomp*2)

InvCDF a05 z05;

Normal 0.0 1.0.

InvCDF a01 z01;

Normal 0.0 1.0.

let z05=absolute(z05)

let z01=absolute(z01)

endif

 

#calculate critical value

let kwk1=(ktotrank*(ktotrank+1)/12)

let cwk1=((1/cssb)+(1/cssa))

let cwk2=(kwk1*cwk1)**0.5

let ccrit05=cwk2*z05

let ccrit01=cwk2*z01

#calculating difference between the groups and finding whether the diff exceeds the critcal difference

 

let diffcol=dcola-dcolb

let diffabs=absolute(diffcol)

let sig05=diffabs>ccrit05

let sig01=diffabs>ccrit01

### oUTPUT

print inputcol ccgb ccga dcolb dcola  diffcol sig05 sig01

 

endmacro

####

macro

phlabels

note: Description of columns : Input column i.e Average ranks

note: nsrno=Group serial number; ccgb=base group; ccga=comparative group

note: dcolb=Average rank of base group; dcola=Average rank of comparative group

note: diffcol=Difference in Average ranks

note: sig05= 1 implies significance at 0.05 level and 0 implies not signficant

note: sig01= 1 implies significance at 0.01 level and 0 implies not signficant

endmacro