[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
khigbee@stata.com |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: more help with mtest needed |

Date |
Fri, 07 Nov 2003 11:15:07 -0600 |

Jim Seward <Jim.Seward@sunhealth.org> asks: > With Ken Higbee's help I was able to find -mtest()-. I'm still not sure > how to use it. > > I have a 2 by 2 anova with insignificant main effects but a signifcant > interaction. I like to explore any differences between cell means. I not > sure how to specify the matrix for -test[matrix name]-. I suppose it's > the design matrix but when I use the "simian" approach and try different > things I get the error message that the matrix is nonconformable. Moments before I saw Jim's statalist posting I had sent him an answer to a similar question that I received privately yesterday. Here is part of what I wrote. First, if you haven't already, look at the FAQs found at http://www.stata.com/support/faqs/stat/#anova In particular, http://www.stata.com/support/faqs/stat/test1.html gives some examples of the -test()- option of -test- after -anova-. Additionally, you might find the following .do files instructive. just copy them out from below and place them in twobytwo.do and paint.do respectively. In stata type -do twobytwo- and then read through the resulting output paying attention to the comments I placed in the do file. Then you can type -do paint- for a more involved example. If your emailer wraps lines, you will have to fix them before running the do files. Ken Higbee khigbee@stata.com StataCorp 1-800-STATAPC *================= Begin of twobytwo.do ============================ * some made up data clear input a b y 1 1 46 1 1 48 1 1 44 1 2 9 1 2 12 1 2 15 2 1 8 2 1 9 2 1 13 2 2 60 2 2 55 2 2 35 end * A look at the data list tabulate a b , summarize(y) means * The standard ANOVA anova y a b a*b * ======================================================== * Do it as a cell means model * group goes 1 to 4 for the 4 cells of the overall model egen group = group(a b) * this table shows how the a and b relate to group tabulate a b, summarize(group) means * this is the cell means model ANOVA * you might consider this output unimportant ... anova y group, noconstant * ... but when you look at the underlying regression ... anova , regress * ... you see the means of your 2x2 table * It is easy to use test after the cell means ANOVA * to get a test of A1 vs A2, B1 vs B2, and the interaction mat A = (1,1,-1,-1) mat B = (1,-1,1,-1) mat AB = (1,-1,-1,1) mat C = A \ B \ AB test , test(C) mtest * lincom is also sometimes helpful * What is the estimate of a1 minus a2 lincom (_b[group[1]] + _b[group[2]] - _b[group[3]] - _b[group[4]])/2 * What is the estimate of b1 minus b2 lincom (_b[group[1]] - _b[group[2]] + _b[group[3]] - _b[group[4]])/2 * If you look back at the original table you will see that the -1 * and -3 answers above agree with subtracting the marginal means * from the table. * ========================================================== * Do it using the "overparameterized" model (standard anova) anova y a b a*b * The regress option shows the underlying regression. (Notice * all the dropped rows. This is why the standard ANOVA approach * is called the "overparameterized" model anova, regress * The showorder option of test will show you the order of * items for creating matrices for the test() option of test. test, showorder * Here are the matrices for testing * The first column is for the constant * The next two columns are for the 2 levels of a * The next two columns are for the 2 levels of b * The last four columns are for the 4 combinations of a and b mat A = (0, 2,-2, 0,0, 1,1,-1,-1) mat B = (0, 0,0, 2,-2, 1,-1,1,-1) mat AB = (0, 0,0, 0,0, 1,-1,-1,1) mat C = A \ B \ AB * And here is the test test , test(C) mtest * Since this is just a 2x2 example, you will notice if you * compare this output with what -anova- gave you -- they are * the same. *=================== End of twobytwo.do ============================ *================= Begin of paint.do =============================== * The following data have been created to closely match the * summary table (Table 8.1) on page 118 of: * Milliken & Johnson (1984). "Analysis of Messy Data, * Volume 1: Designed Experiments", Van Nostrand * Reinhold Company. clear input paint paving lifetime 1 1 10.5 1 1 15 1 1 19.5 1 2 22.5 1 2 17 1 2 11.5 1 3 28 1 3 32 1 3 36 2 1 22.5 2 1 27 2 1 31.5 2 2 35 2 2 30 2 2 25 2 3 16 2 3 20 2 3 24 3 1 34 3 1 30 3 1 26 3 2 25 3 2 28 3 2 31 3 3 24 3 3 29 3 3 34 4 1 31 4 1 34 4 1 37 4 2 30 4 2 35 4 2 40 4 3 32 4 3 36 4 3 40 end compress label define paint 1 "Yellow I" 2 "Yellow II" 3 "White I" 4 "White II" label define paving 1 "Asphalt I" 2 "Asphalt II" 3 "Concrete" label values paint paint label values paving paving * This matches Table 8.1 tabulate paint paving, summarize(lifetime) nostandard nofreq * This matches closely the ANOVA table shown in Table 8.2 * (small differences in Residual and Total Error due to me * creating the data as best I could from just the means from * Table 8.1.) anova lifetime paint paving paint*paving * The -showorder- option of -test- indicates the number of * columns and what they represent test, showorder * In the book they set out 3 interesting contrasts on paints * (see Table 8.3) * c1 is for Yellow I vs. Yellow II mat c1 = (0, 3,-3,0,0, 0,0,0, 1,1,1,-1,-1,-1,0,0,0,0,0,0) * c2 is for White I vs. White II mat c2 = (0, 0,0,3,-3, 0,0,0, 0,0,0,0,0,0,1,1,1,-1,-1,-1) * c3 is for Yellow vs. White mat c3 = (0, 3,3,-3,-3, 0,0,0, 1,1,1,1,1,1,-1,-1,-1,-1,-1,-1) * They indicate 2 interesting contrasts on pavement * c4 is for Asphalt I vs. Asphalt II mat c4 = (0, 0,0,0,0, 4,-4,0, 1,-1,0,1,-1,0,1,-1,0,1,-1,0) * c5 is for Asphalt vs. Concrete mat c5 = (0, 0,0,0,0, 4,4,-8, 1,1,-2,1,1,-2,1,1,-2,1,1,-2) * In Table 8.4 they show 6 contrasts for the paint*pavement * interaction. I could just type them out, but instead I * use some loops and create them from the c1 - c5 I already * have forvalues j=4/5 { forvalues i=1/3 { mat c`i'`j' = J(1,20,0) forvalues k=1/20 { mat c`i'`j'[1,`k'] = c`i'[1,`k'] * c`j'[1,`k'] } } } * I can combine these row vectors together into a matrix with * 11 rows and 20 columns mat C = c1 \ c2 \ c3 \ c4 \ c5 \ c14 \ c24 \ c34 \ c15 \ c25 \ c35 mat list C * Now I can use that C matrix in the -test()- option of -test- * The -mtest- option gives me the results for each row test, test(C) mtest * I could get Bonferroni adjusted p-values with test, test(C) mtest(bonferroni) *=================== End of paint.do =============================== * * 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/

- Prev by Date:
**Re: st: clogit or logistic for matched pairs** - Next by Date:
**st: testing coefficients across samples that are nested** - Previous by thread:
**st: more help with mtest needed** - Index(es):

© Copyright 1996–2015 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |