Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re: st: How to graph means with correct SE after repeated ANOVA?


From   "RAMPL Linn" <Linn.RAMPL@insead.edu>
To   <statalist@hsphsun2.harvard.edu>
Subject   Re: Re: st: How to graph means with correct SE after repeated ANOVA?
Date   Fri, 26 Mar 2010 15:04:52 +0100

ANOVA?

>I am trying to graph the means of a 2-way REPEATED ANOVA in bar charts
>and would like to include the correct standard errors.
>
>Here is how I would do this in a BETWEEN subject 2-way ANOVA:

>Linn-

>I can see where your going with your code but I think there is an
>easier way using -xtmixed- and -margins-.  You can use -margins- to
>obtain the adjusted cell means along with their standard errors.  We
>have a web page which covers graphing but not specifically for
>repeated measures:

>http://www.ats.ucla.edu/stat/stata/faq/mar_graph/margins_graph.htm

>Phil

Dear Phil and Dave,

THANK you so much for your advices. In particularly the URL you gave me,
Phil, helped a lot. Since the homepage only provides the information how
to graph a dot-chart, here's what I did to graph a bar chart for a 2-way
mixed ANOVA including the SE:

------------------------------------------------------------------------
-
**** Repeated 2-way anova
* Y = diff_rate
* subject (repeated) = matlab_file
* X1 = trial_2 (0, 1)
* X2 = frequency (0, 1)

anova diff_rate matlab_file trial_2 / matlab_file#trial_2 frequency /
matlab_file#frequency trial_2#frequency, repeated(trial_2 frequency)

*marginal means including 95% confidence interval
margins trial_2#frequency, asbalanced emptycells(reweight) 

*saving information from marginal means in matrices
matrix b=r(b)' //matrix including means of diff_rate for trial_2 (0, 1)

matrix prg=(0\1)#(1\1)  /* # is the kronecker product operator */
matrix list prg

matrix low=(1\1)#(0\1)  /* # is the kronecker product operator */
matrix list low

matrix c=prg,low,b
matrix list c

svmat c, names(c)
list c1-c3 in 1/4

matrix v=r(V)
matrix v=v[1...,1...]
matrix list v

matrix se=vecdiag(cholesky(diag(vecdiag(v))))'
matrix list se

matrix d=b,se
matrix list d

svmat d, names(d)
generate ul = d1 + 1.96*d2
generate ll = d1 - 1.96*d2
list d1-ll in 1/4

* Build a two-way bar graph
generate  group_trial_2_frequency = .
replace group_trial_2_frequency = 0 in 1
replace group_trial_2_frequency = 1 in 2
replace group_trial_2_frequency = 3 in 3
replace group_trial_2_frequency = 4 in 4

twoway (bar d1 group_trial_2_frequency if c2 == 0, color(gs2)) (bar d1
group_trial_2_frequency if c2 == 1, color(gs11)) (rcap ul ll
group_trial_2_frequency, blcolor(gs1))
------------------------------------------------------------------------
-

So this finally worked out, thank you so much.

However, I am not sure how the "margins" command works after a repeated
anova command, since STANDARD ERRORS reported in one group ARE EXACTLY
THE SAME:

-----------------------------------------------------------------------
  |            Delta-method
  |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+---------------------------------------------------------
trial_2 |
     0  |   1.282051   .1263909    10.14   0.000      1.03433
1.529773
     1  |  -.5940171   .1263909    -4.70   0.000    -.8417386
-.3462956
      
frequency |
       0  |   .4679487   .1263909     3.70   0.000     .2202272
.7156702
       1  |   .2200855   .1263909     1.74   0.082     -.027636
.467807
      
  trial_2#|
frequency |
     0 0  |   1.435897   .1787437     8.03   0.000     1.085566
1.786229
     0 1  |   1.128205   .1787437     6.31   0.000      .777874
1.478536
     1 0  |        -.5   .1787437    -2.80   0.005    -.8503311
-.1496689
     1 1  |  -.6880342   .1787437    -3.85   0.000    -1.038365
-.3377031
-----------------------------------------------------------------------

I looked up http://www.ats.ucla.edu/stat/stata/faq/margins_nested1.htm
where you see a similar situation for the SE. 

WHY ARE THE SE exactly the SAME? In particular, the consequence is, that
the confidence intervals in one group have the same range (i.e. the same
absolute difference). Is this a mistake or correct? If this is correct
then graphing confidence intervals in this case would not make a lot of
sense...!

Thank you so much for any advice!

Best Linn

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index