|
|
|
||||
|
Help the Stat Consulting Group by
giving a gift
| |||||
|
Loading
|
|||||
Chapter 12, page 257 shows how to perform an interaction contrast using the data from chapter 10.
use http://www.ats.ucla.edu/stat/stata/examples/da/chap10, clear
This interaction contrast compares a2 with a3 for factor a and compares b1 with b2 for factor b. First, let's create the contrasts for factor a. We will also create a second comparison for factor a that is orthogonal to the first comparison.
char a[user] (0 -1 1\2 -1 -1)
Now let's create the contrast for factor b.
char b[user] (1 -1)
Now, let's perform the interaction comparison by using u.a*u.b after the regress command. The interaction contrast is reflected in the product of the first comparison on a and the first (and only) comparison on b, so it is the term _Ia1Xb1 that is of interest. We show the test command for this simply to show the F value for this test and that it matches the text. You can download the xi3 command by typing findit xi3 (see How can I use the findit command to search for programs and get additional help? for more information about using findit).
xi3: regress errors u.a*u.b
u.a _Ia_1-3 (naturally coded; _Ia_3 omitted)
u.b _Ib_1-2 (naturally coded; _Ib_2 omitted)
Source | SS df MS Number of obs = 24
-------------+------------------------------ F( 5, 18) = 3.05
Model | 280 5 56 Prob > F = 0.0361
Residual | 330 18 18.3333333 R-squared = 0.4590
-------------+------------------------------ Adj R-squared = 0.3087
Total | 610 23 26.5217391 Root MSE = 4.2817
------------------------------------------------------------------------------
errors | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_Ia_1 | 1 2.140872 0.47 0.646 -3.497805 5.497805
_Ia_2 | -9 3.708099 -2.43 0.026 -16.79043 -1.209573
_Ib_1 | -2 1.748015 -1.14 0.268 -5.672443 1.672443
_Ia1Xb1 | 6 4.281744 1.40 0.178 -2.995611 14.99561
_Ia2Xb1 | -18 7.416198 -2.43 0.026 -33.58085 -2.419145
_cons | 10 .8740074 11.44 0.000 8.163779 11.83622
------------------------------------------------------------------------------
test _Ia1Xb1
( 1) _Ia1Xb1 = 0
F( 1, 18) = 1.96
Prob > F = 0.1781
The effect _Ia2Xb1 reflects the second comparison on a at b1, and this is the comparison shown in the middle of page 259, see below.
test _Ia2Xb1
( 1) _Ia2Xb1 = 0
F( 1, 18) = 5.89
Prob > F = 0.0259
On page 264-265 Keppel shows another interaction contrast. We compute the coefficients for these contrasts below.
use http://www.ats.ucla.edu/stat/stata/examples/da/chap12, clear char a[user] (1 -.5 -.5\0 1 -1) char b[user] (0 1 -1\2 -1 -1)
Now we run the analysis using u.a*u.b and the _Ia1Xb1 term corresponds to the first comparison on a crossed with the first comparison on b. We show the test command for this term and this matches the result shown by Keppel at the top of page 265 (with a bit of rounding error).
xi3: regress memory u.a*u.b
u.a _Ia_1-3 (naturally coded; _Ia_3 omitted)
u.b _Ib_1-3 (naturally coded; _Ib_3 omitted)
Source | SS df MS Number of obs = 45
-------------+------------------------------ F( 8, 36) = 9.26
Model | 129.199997 8 16.1499997 Prob > F = 0.0000
Residual | 62.8200027 36 1.74500008 R-squared = 0.6728
-------------+------------------------------ Adj R-squared = 0.6001
Total | 192.02 44 4.36409091 Root MSE = 1.321
------------------------------------------------------------------------------
memory | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_Ia_1 | 1.8 .417732 4.31 0.000 .9528003 2.6472
_Ia_2 | .2666666 .4823553 0.55 0.584 -.7115954 1.244929
_Ib_1 | 2.733333 .4823553 5.67 0.000 1.755071 3.711595
_Ib_2 | 2.6 .835464 3.11 0.004 .9056006 4.294399
_Ia1Xb1 | -2.9 1.02323 -2.83 0.007 -4.975207 -.8247928
_Ia1Xb2 | -3.899999 1.772287 -2.20 0.034 -7.494363 -.3056354
_Ia2Xb1 | -.2000004 1.181524 -0.17 0.867 -2.596243 2.196242
_Ia2Xb2 | -1.399999 2.04646 -0.68 0.498 -5.550413 2.750415
_cons | 7.2 .1969207 36.56 0.000 6.800626 7.599374
------------------------------------------------------------------------------
test _Ia1Xb1
( 1) _Ia1Xb1 = 0
F( 1, 36) = 8.03
Prob > F = 0.0075
On page 269/270, Keppel illustrates another interaction contrast. Below we use the chap10 data file.
use http://www.ats.ucla.edu/stat/stata/examples/da/chap10, clear
The comparisons on a are orthogonal polynomial comparisons and can be achieved with the o. suffix (i.e., o.a) and the comparison on be is a simple comparison comparing b1 with b2 so we can use s.b, as shown below. The effect _Ia1Xb2 is the linear effect of a crossed with b and corresponds to that shown by Keppel at the top of page 270, see the test command below.
xi3: regress errors o.a*g.b
o.a _Ia_1-3 (_Ia_3 for a==3 omitted)
g.b _Ib_1-2 (naturally coded; _Ib_1 omitted)
Source | SS df MS Number of obs = 24
-------------+------------------------------ F( 5, 18) = 3.05
Model | 280 5 56 Prob > F = 0.0361
Residual | 330 18 18.3333333 R-squared = 0.4590
-------------+------------------------------ Adj R-squared = 0.3087
Total | 610 23 26.5217391 Root MSE = 4.2817
------------------------------------------------------------------------------
errors | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_Ia_1 | 2.041241 .8740074 2.34 0.031 .2050201 3.877463
_Ia_2 | -.7071068 .8740074 -0.81 0.429 -2.543328 1.129115
_Ib_2 | 2 1.748015 1.14 0.268 -1.672443 5.672443
_Ia1Xb2 | -4.898979 1.748015 -2.80 0.012 -8.571422 -1.226537
_Ia2Xb2 | -1.52e-16 1.748015 -0.00 1.000 -3.672443 3.672443
_cons | 10 .8740074 11.44 0.000 8.163779 11.83622
------------------------------------------------------------------------------
test _Ia1Xb2
( 1) _Ia1Xb2 = 0
F( 1, 18) = 7.85
Prob > F = 0.0118
On pages 270 to 274 Keppel shows how to perform a partial interaction that compares a1 versus a2 and a3 by b. We start by creating the contrast corresponding to this comparison, and creating a second contrast which is orthogonal to acomp1.
use http://www.ats.ucla.edu/stat/stata/examples/da/chap12, clear char a[user] (-2 1 1\0 -1 1)
Now, we use the user-defined contrasts that we made with the char command above. When we combine the all of the tests of the first comparison on a crossed with b, we get the Acomp by B effect described in Keppel. So we test _Ia1Xb2 _Ia1Xb3 and we get the result shown in the top portion of page 274.
xi3: regress memory u.a*g.b
u.a _Ia_1-3 (naturally coded; _Ia_3 omitted)
g.b _Ib_1-3 (naturally coded; _Ib_1 omitted)
Source | SS df MS Number of obs = 45
-------------+------------------------------ F( 8, 36) = 9.26
Model | 129.199997 8 16.1499997 Prob > F = 0.0000
Residual | 62.8200027 36 1.74500008 R-squared = 0.6728
-------------+------------------------------ Adj R-squared = 0.6001
Total | 192.02 44 4.36409091 Root MSE = 1.321
------------------------------------------------------------------------------
memory | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_Ia_1 | -3.6 .835464 -4.31 0.000 -5.294399 -1.905601
_Ia_2 | -.2666666 .4823553 -0.55 0.584 -1.244929 .7115954
_Ib_2 | .0666667 .4823553 0.14 0.891 -.9115953 1.044929
_Ib_3 | -2.666667 .4823553 -5.53 0.000 -3.644929 -1.688405
_Ia1Xb2 | -.9999996 2.04646 -0.49 0.628 -5.150414 3.150414
_Ia1Xb3 | -6.799999 2.04646 -3.32 0.002 -10.95041 -2.649585
_Ia2Xb2 | -.5999994 1.181524 -0.51 0.615 -2.996242 1.796243
_Ia2Xb3 | -.7999998 1.181524 -0.68 0.503 -3.196242 1.596243
_cons | 7.2 .1969207 36.56 0.000 6.800626 7.599374
------------------------------------------------------------------------------
test _Ia1Xb2 _Ia1Xb3
( 1) _Ia1Xb2 = 0
( 2) _Ia1Xb3 = 0
F( 2, 36) = 6.44
Prob > F = 0.0041
UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services