st: RE: multiple comparisons again

 From "FEIVESON, ALAN H. (AL) (JSC-SK) (NASA)" To "'statalist@hsphsun2.harvard.edu'" Subject st: RE: multiple comparisons again Date Wed, 9 Apr 2003 09:07:06 -0500

Sven-Erik

This is a rather crude program I wrote that does Scheffe pairwise
comparisons for a oneway repeated design. The calling sequence would be

schefrpm y sub treat

where  `y' is the dependent variable, `sub' is the random factor that is
repeated and `treat' is a fixed treatment factor. The model is given as a
comment in the program below. WHen you run this program you get:

1. The ANOVA output

2. A list of treatment means and est. sd's

3. A list of all pairwise comparisons with adjusted F and and P-values. For
example

3  2     -0.21    0.5349

means the comparison of level 3 with level 2 of the treatment factor, the
F-value was -0.21 and the P-value was 0.5349.

4. There is a bunch of other stuff, like degrees of freedom stored in
scalars.

program define schefrpm
/* Scheffe contrast tests for repeated measures design
yij = u + ai + bej + eij
ai = random subject effect
bj = fixed treatment effect                          */

/* `1' is dep; `2' is subjects; `3' is treatments  */
version 5.0
anova `1' `2' `3'
scalar s2 = e(rss)/e(df_r) /* _result(4)/_result(5)  */
local df2=e(df_r)          /* _result(5)             */
qui tab `3'
scalar k = r(r)     /* number of treatments  */
local k=scalar(k)
preserve
collapse (mean) y=`1' (count) n=`1' (sd) sd=`1' ,by(`3')

label var y "average"
format y  sd %8.2f
list
local i=0
while `i' < `k' {
local i=`i' + 1
local j=0
while `j' < `i'-1 {
local j=`j'+1
scal dif=y[`i']-y[`j']
scal var=s2*(1/n[`i']+1/n[`j'])
scal t2=dif*dif/var
local F=t2/(`k'-1)
local df1=`k'-1
scal F`i'`j'=`F'
scal df1`i'`j'=`df1'
scal df2`i'`j'=`df2'

scal P`i'`j' = fprob(`df1',`df2',`F')
di `i' "  " `j' "  " %8.2f dif  "  "  %8.4f P`i'`j'
}
}
restore
end

Hopefully, this could be of some use to you.

AL Feiveson
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/