0% found this document useful (0 votes)
138 views8 pages

Stata Output For ANCOVA Section

An analysis of variance (ANOVA) was conducted on children's birth weights using number of cigarettes smoked by the mother during pregnancy (ms_gp) as a factor. The ANOVA found a significant effect of ms_gp on birth weight. An analysis of covariance (ANCOVA) was then performed, controlling for maternal pre-pregnancy weight, and again found a significant effect of ms_gp on birth weight. Finally, an ANCOVA with an interaction term was run to test for unequal slopes but no significant interaction was found.

Uploaded by

juntujuntu
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
138 views8 pages

Stata Output For ANCOVA Section

An analysis of variance (ANOVA) was conducted on children's birth weights using number of cigarettes smoked by the mother during pregnancy (ms_gp) as a factor. The ANOVA found a significant effect of ms_gp on birth weight. An analysis of covariance (ANCOVA) was then performed, controlling for maternal pre-pregnancy weight, and again found a significant effect of ms_gp on birth weight. Finally, an ANCOVA with an interaction term was run to test for unequal slopes but no significant interaction was found.

Uploaded by

juntujuntu
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Stata Output for ANCOVA Section, Spring 2006

1.

One-Way ANOVA on Birth Weights

Child's birth weight (lbs)


6
8
10

12

. graph box weight,over(ms_gp) b1title("Packs of cigarettes mother smoked")

Packs of cigarettes mother smoked

. anova weight ms_gp


Number of obs =
680
Root MSE
= 1.06613

R-squared
=
Adj R-squared =

0.0502
0.0474

Source | Partial SS
df
MS
F
Prob > F
-----------+---------------------------------------------------Model | 40.7012466
2 20.3506233
17.90
0.0000
|
ms_gp | 40.7012466
2 20.3506233
17.90
0.0000
|
Residual |
769.4943
677 1.13662378
-----------+---------------------------------------------------Total | 810.195546
679 1.19321877
. anova,regress /* get contrasts vs. last group*/
Source |
SS
df
MS
-------------+-----------------------------Model | 40.7012466
2 20.3506233
Residual |
769.4943
677 1.13662378
-------------+-----------------------------Total | 810.195546
679 1.19321877

Number of obs
F( 2,
677)
Prob > F
R-squared
Adj R-squared
Root MSE

=
=
=
=
=
=

680
17.90
0.0000
0.0502
0.0474
1.0661

-----------------------------------------------------------------------------weight
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-----------------------------------------------------------------------------_cons
7.266154
.0935054
77.71
0.000
7.082558
7.449749
ms_gp
1
.4666546
.1082891
4.31
0.000
.2540318
.6792774
2
-.0448521
.1243738
-0.36
0.718
-.2890568
.1993527
3
(dropped)
-----------------------------------------------------------------------------. lincom(_b[ms_gp[1]]-_b[ms_gp[2]]) /*non- vs. light-smoke contrast*/
( 1)

ms_gp[1] - ms_gp[2] = 0

-----------------------------------------------------------------------------weight |
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-------------+---------------------------------------------------------------(1) |
.5115066
.0985335
5.19
0.000
.3180387
.7049746
------------------------------------------------------------------------------

Stata Output for ANCOVA section, Spring 2006, Page 1 of 8

. *get same analysis using xi command (parameter constraints differ)


. xi:regress weight i.ms_gp
i.ms_gp
_Ims_gp_0-2

(naturally coded; _Ims_gp_0 omitted)

Source |
SS
df
MS
-------------+-----------------------------Model | 40.7012466
2 20.3506233
Residual |
769.4943
677 1.13662378
-------------+-----------------------------Total | 810.195546
679 1.19321877

Number of obs
F( 2,
677)
Prob > F
R-squared
Adj R-squared
Root MSE

=
=
=
=
=
=

680
17.90
0.0000
0.0502
0.0474
1.0661

-----------------------------------------------------------------------------weight |
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-------------+---------------------------------------------------------------_Ims_gp_1 | -.5115066
.0985335
-5.19
0.000
-.7049746
-.3180387
_Ims_gp_2 | -.4666546
.1082891
-4.31
0.000
-.6792774
-.2540318
_cons |
7.732808
.0546193
141.58
0.000
7.625565
7.840052
-----------------------------------------------------------------------------. testparm _Ims_gp*
( 1)
( 2)

_Ims_gp_1 = 0
_Ims_gp_2 = 0
F(

2,
677) =
17.90
Prob > F =
0.0000
. lincom(_b[_Ims_gp_1]-_b[_Ims_gp_2])
( 1)

_Ims_gp_1 - _Ims_gp_2 = 0

-----------------------------------------------------------------------------weight |
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-------------+---------------------------------------------------------------(1) | -.0448521
.1243738
-0.36
0.718
-.2890568
.1993527
------------------------------------------------------------------------------

2.

ANCOVA on Birth Weights

. *fit pre-pregnancy weight as covariate using anova command


. anova weight ms_gp mweight,cont(mweight)
Number of obs =
680
Root MSE
= 1.04627

R-squared
=
Adj R-squared =

0.0866
0.0826

Source | Partial SS
df
MS
F
Prob > F
-----------+---------------------------------------------------Model | 70.1883192
3 23.3961064
21.37
0.0000
|
ms_gp | 30.4085011
2 15.2042506
13.89
0.0000
mweight | 29.4870727
1 29.4870727
26.94
0.0000
|
Residual | 740.007227
676 1.09468525
-----------+---------------------------------------------------Total | 810.195546
679 1.19321877

. anova,regress /*get contrasts vs. last group*/


Source |
SS
df
MS
-------------+-----------------------------Model | 70.1883192
3 23.3961064
Residual | 740.007227
676 1.09468525
-------------+-----------------------------Total | 810.195546
679 1.19321877

Number of obs
F( 3,
676)
Prob > F
R-squared
Adj R-squared
Root MSE

=
=
=
=
=
=

680
21.37
0.0000
0.0866
0.0826
1.0463

-----------------------------------------------------------------------------weight
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-----------------------------------------------------------------------------_cons
5.751662
.3058953
18.80
0.000
5.151043
6.352282
ms_gp
1
.4477316
.106335
4.21
0.000
.238945
.6565182

Stata Output for ANCOVA section, Spring 2006, Page 2 of 8

2
3

.0318146
.1229483
0.26
0.796
-.2095919
.2732211
(dropped)
mweight
.0118683
.0022868
5.19
0.000
.0073784
.0163583
-----------------------------------------------------------------------------. lincom(_b[ms_gp[1]]-_b[ms_gp[2]]) /*non- vs. light-smoke contrast*/
( 1)

ms_gp[1] - ms_gp[2] = 0

-----------------------------------------------------------------------------weight |
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-------------+---------------------------------------------------------------(1) |
.415917
.098437
4.23
0.000
.222638
.6091959
------------------------------------------------------------------------------

. *repeat using xi (get different contrasts)


. xi: regress weight i.ms_gp mweight
i.ms_gp
_Ims_gp_0-2

(naturally coded; _Ims_gp_0 omitted)

Source |
SS
df
MS
-------------+-----------------------------Model | 70.1883192
3 23.3961064
Residual | 740.007227
676 1.09468525
-------------+-----------------------------Total | 810.195546
679 1.19321877

Number of obs
F( 3,
676)
Prob > F
R-squared
Adj R-squared
Root MSE

=
=
=
=
=
=

680
21.37
0.0000
0.0866
0.0826
1.0463

-----------------------------------------------------------------------------weight |
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-------------+---------------------------------------------------------------_Ims_gp_1 |
-.415917
.098437
-4.23
0.000
-.6091959
-.222638
_Ims_gp_2 | -.4477316
.106335
-4.21
0.000
-.6565182
-.238945
mweight |
.0118683
.0022868
5.19
0.000
.0073784
.0163583
_cons |
6.199394
.300276
20.65
0.000
5.609808
6.78898
. testparm _Ims_gp*
( 1)
( 2)

_Ims_gp_1 = 0
_Ims_gp_2 = 0
F(

2,
676) =
Prob > F =

13.89
0.0000

. lincom(_b[_Ims_gp_1]-_b[_Ims_gp_2])
( 1)

_Ims_gp_1 - _Ims_gp_2 = 0

-----------------------------------------------------------------------------weight |
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-------------+---------------------------------------------------------------(1) |
.0318146
.1229483
0.26
0.796
-.2095919
.2732211

12

. *get fitted lines plotted on scatter plots


. predict yhat
(option xb assumed; fitted values)
. twoway (scatter weight mweight, mlabel(ms_gp)) ///
>
(line yhat mweight if ms_gp==0) (line yhat mweight if ms_gp==1) ///
>
(line yhat mweight if ms_gp ==2), legend(off)

0
0
0

0
00
0 0
10
0
1
1
11 00
1 0
201
1 00
10 0 0
0
2
00 0 0 0
0
0 02 0
00
1
01
0021 02
2
1
2
0
0
0
0 2
0 20 1 12 10 00 202
02
0
2
0
0
1
02 00 0 10 0 011
2
0
0
00201
0
02
0 0 000 0 0 2 0 0
0 0001
00 0 1
022
0 02
1
0 00
0 02
01 1
20 0
0
0 0 0120 0
0 0 0 20
021
0
11
0 1
11 020
02
20
00
0000
000
02
12
00
011
02
0 1
0 00 00 0
1
00
0
1
0
0
0
0
01 0 011
0
0
001
0 02
2
0
012
0 2 00
1002
000
02
00
0
1
02
2
0
0
0
0
0
1
1
11
0
0
1
0
0
1
0
0
1
0
0
2
0
2
0
0
20
1 00
01
212
011
02
02
122 0
00
01
10
2
01
2
0000 2
0 002 0 0
0
02
01
0
010
0 2 011 001
01
1
011
11
2
00
00
10011000
2
22
000 2
00 010
12
012
02 1
00
1 11
0
021
0
0
1
2010 0
010
00
2
012
1
02
1
002
1
020
22
2
001
2
11 1 0 0
2
0 210
01
100
00001
12
2
1
2
0011
02
02
02
1
00
00 0 2
200
0
1
11
0
0
0
2
0
1002
0 1
02 01
01122
2010 00
0 1
0 01
01
0
2 1 1 100 221 1
0
0101 2
1
22
012 0 0
2
0 2
122 1 2 1
11 0
0
1
0 01
1
0 0
11
2
100
1 10111
21122
1 2 02 2
0 1 2 2 11
0
1 2 101 210
0
2
0
2 110 1 2
1
00 1
1
0
0
2
2
2

10

0
0
2
0

0
0

50

100
150
200
Maternal pre-pregnancy weight (lb)

250

Stata Output for ANCOVA section, Spring 2006, Page 3 of 8

4
2
Residuals
0
-2
-4
6.5

3.

7.5
8
Fitted values

8.5

ANCOVA with interaction

. *fit unequal slopes


. anova weight ms_gp mweight ms_gp*mweight,cont(mweight)
Number of obs =
680
Root MSE
= 1.04566

R-squared
=
Adj R-squared =

0.0904
0.0836

12

Source | Partial SS
df
MS
F
Prob > F
--------------+---------------------------------------------------Model |
73.234203
5 14.6468406
13.40
0.0000
|
ms_gp | 2.87983773
2 1.43991886
1.32
0.2687
mweight | 23.4430881
1 23.4430881
21.44
0.0000
ms_gp*mweight | 3.04588372
2 1.52294186
1.39
0.2491
|
Residual | 736.961343
674 1.09341446
--------------+---------------------------------------------------Total | 810.195546
679 1.19321877
0
0
0

0
00
0 0
10
1
1
11 00
1 0
0
0
201
1 0
01 0
0 0
2
0 1
0 0 0
0
0
0
0
0
0
2
0
2
1 2120 01021 2
2 00 0 02
0 20 2
0 0 2
1
1
0
00
0
2
0
0
1
02 00 0 10 0 011
200
002
00
02
02
0 0 000 0 0 2 0 0
0 0001
00 0 1
022
0
1
1
0 00
0 02
01 1
200 0
0
0 0 0120 0
0 0 0 20
021
01
11
0 1
1
1
0
2
0
0
0
0
0
0
0
0
0
0
0
1 010202 00
00
0
0
0
202
0
1
0
1
0 0 000 00 0
1
0
0000
02
00
001
2
02
00212
2
0 2
0001
11
1002
0
00
1
1
0
0
0
0
0
1
11
0
0
1
0
0
1
0
0
1
2
0
0
2
0
2
0
0
20
1 00
01
212
011
02
02
122 0
00
01
10
2
01
2
0000 2
0 002 0 0
0
02
01
0
010
0 2 011 001
01
02
1
00
1
2
011000
22
000 2
00 0010
12
1
11
1
02
000
012
02 1
00
1 11
0
021
0
001
2
02
10
2 10 2
010
00
012
1
02
1
00022
1
2
11 1 0 0
0 212
01
10
0 000
12
2
00
1
2
0011
02
02
02
1
000
0
00 0 2
1
200
0
1
11
0
2
0
1002
0 1
02 01
01122
0
0 01
1
022
10120000
0 0
2 1 1 100 221 1
0
2
0101 2
1
0
1
2111112
11 0
0
1
0 01
122 102 2
01
1
101
0 10
1
1 2 22
1 02 02 2
0 1 2 2 11
0
1 2 0 210
02 0
2 1101 11 2
1
1
0
1
0
0
0
2
2
2

10

0
2
0

0
0

50

100
150
200
Maternal pre-pregnancy weight (lb)

250

. anova,regress
Source |
SS
df
MS
-------------+-----------------------------Model |
73.234203
5 14.6468406
Residual | 736.961343
674 1.09341446
-------------+-----------------------------Total | 810.195546
679 1.19321877

Number of obs
F( 5,
674)
Prob > F
R-squared
Adj R-squared
Root MSE

=
=
=
=
=
=

680
13.40
0.0000
0.0904
0.0836
1.0457

-----------------------------------------------------------------------------weight
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-----------------------------------------------------------------------------_cons
6.471542
.5897484
10.97
0.000
5.313577
7.629508
ms_gp
1
-.3684091
.7043394
-0.52
0.601
-1.751372
1.014554
2
-1.470025
.9305639
-1.58
0.115
-3.297178
.3571275
3
(dropped)
mweight
.006227
.0045654
1.36
0.173
-.002737
.015191
ms_gp*mweight
1
.0063864
.0054363
1.17
0.241
-.0042878
.0170606
2
.0120959
.0074636
1.62
0.106
-.0025588
.0267506
3
(dropped)
------------------------------------------------------------------------------

Stata Output for ANCOVA section, Spring 2006, Page 4 of 8

Look at the 3 separate linear regressions


. *do 3 separate linear regressions to see same as above
. regress weight mweight if ms_gp==0
Source |
SS
df
MS
-------------+-----------------------------Model | 19.9691724
1 19.9691724
Residual | 400.850734
379 1.05765365
-------------+-----------------------------Total | 420.819907
380 1.10742081

Number of obs
F( 1,
379)
Prob > F
R-squared
Adj R-squared
Root MSE

=
=
=
=
=
=

381
18.88
0.0000
0.0475
0.0449
1.0284

-----------------------------------------------------------------------------weight |
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-------------+---------------------------------------------------------------mweight |
.0126134
.0029028
4.35
0.000
.0069057
.0183211
_cons |
6.103133
.3787358
16.11
0.000
5.358447
6.84782
-----------------------------------------------------------------------------. regress weight mweight if ms_gp==1
Source |
SS
df
MS
-------------+-----------------------------Model | 10.5295899
1 10.5295899
Residual |
184.61373
167 1.10547144
-------------+-----------------------------Total |
195.14332
168 1.16156738

Number of obs
F( 1,
167)
Prob > F
R-squared
Adj R-squared
Root MSE

=
=
=
=
=
=

169
9.52
0.0024
0.0540
0.0483
1.0514

-----------------------------------------------------------------------------weight |
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-------------+---------------------------------------------------------------mweight |
.0183229
.0059369
3.09
0.002
.0066018
.0300441
_cons |
5.001517
.7237813
6.91
0.000
3.572577
6.430458
-----------------------------------------------------------------------------. regress weight mweight if ms_gp==2
Source |
SS
df
MS
-------------+-----------------------------Model | 2.03419408
1 2.03419408
Residual | 151.496879
128 1.18356937
-------------+-----------------------------Total | 153.531073
129 1.19016336

Number of obs
F( 1,
128)
Prob > F
R-squared
Adj R-squared
Root MSE

=
=
=
=
=
=

130
1.72
0.1922
0.0132
0.0055
1.0879

-----------------------------------------------------------------------------weight |
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-------------+---------------------------------------------------------------mweight |
.006227
.0047498
1.31
0.192
-.0031714
.0156253
_cons |
6.471542
.6135801
10.55
0.000
5.257469
7.685615
------------------------------------------------------------------------------

Stata Output for ANCOVA section, Spring 2006, Page 5 of 8

4.

ANCOVA with several covariates

. *fit mother's age, height, and gest length in addition to mother's age
. anova weight ms_gp mweight mage mheight gest,cat(ms_gp)
Number of obs =
680
Root MSE
= .945452

R-squared
=
Adj R-squared =

0.2575
0.2509

Source | Partial SS
df
MS
F
Prob > F
-----------+---------------------------------------------------Model | 208.614176
6 34.7690293
38.90
0.0000
|
ms_gp | 21.4974642
2 10.7487321
12.02
0.0000
mweight | 8.81068556
1 8.81068556
9.86
0.0018
mage | .261046609
1 .261046609
0.29
0.5891
mheight | 8.85729309
1 8.85729309
9.91
0.0017
gest | 127.058652
1 127.058652
142.14
0.0000
|
Residual |
601.58137
673 .893880194
-----------+---------------------------------------------------Total | 810.195546
679 1.19321877
. anova,regress
Source |
SS
df
MS
-------------+-----------------------------Model | 208.614176
6 34.7690293
Residual |
601.58137
673 .893880194
-------------+-----------------------------Total | 810.195546
679 1.19321877

Number of obs
F( 6,
673)
Prob > F
R-squared
Adj R-squared
Root MSE

=
=
=
=
=
=

680
38.90
0.0000
0.2575
0.2509
.94545

-----------------------------------------------------------------------------weight
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-----------------------------------------------------------------------------_cons
-6.243737
1.242411
-5.03
0.000
-8.683205
-3.804269
ms_gp
1
.4064518
.0964457
4.21
0.000
.2170811
.5958225
2
.0844867
.1112774
0.76
0.448
-.134006
.3029794
3
(dropped)
mweight
.0074945
.0023872
3.14
0.002
.0028074
.0121817
mage
-.0036179
.0066949
-0.54
0.589
-.0167633
.0095274
mheight
.0530975
.016868
3.15
0.002
.0199773
.0862177
gest
.2321497
.0194718
11.92
0.000
.1939169
.2703824
-----------------------------------------------------------------------------. lincom(_b[ms_gp[1]]-_b[ms_gp[2]]) /*non- vs. light-smoke contrast*/
( 1)

ms_gp[1] - ms_gp[2] = 0

-----------------------------------------------------------------------------weight |
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-------------+---------------------------------------------------------------(1) |
.3219651
.0893562
3.60
0.000
.1465146
.4974156
------------------------------------------------------------------------------

Stata Output for ANCOVA section, Spring 2006, Page 6 of 8

Simulated Data Set 1

5.

. anova y group /* ignore covariate */


Number of obs =
63
Root MSE
= 1.08223

R-squared
= 0.0095
Adj R-squared = -0.0235

Source | Partial SS
df
MS
F
Prob > F
-----------+---------------------------------------------------Model | .672876396
2 .336438198
0.29
0.7513
|
group | .672876396
2 .336438198
0.29
0.7513
|
Residual |
70.27336
60 1.17122267
-----------+---------------------------------------------------Total | 70.9462364
62 1.14429413
. anova y group x,cont(x) /* include covariate */
Number of obs =
63
Root MSE
= .525494

R-squared
=
Adj R-squared =

0.7704
0.7587

Source | Partial SS
df
MS
F
Prob > F
-----------+---------------------------------------------------Model | 54.6537313
3 18.2179104
65.97
0.0000
|
group | 24.3554868
2 12.1777434
44.10
0.0000
x | 53.9808549
1 53.9808549
195.48
0.0000
|
Residual | 16.2925051
59 .276144154
-----------+---------------------------------------------------Total | 70.9462364
62 1.14429413

3
2 2

2
1

3
3

3
3

3
3

1
1
2

2
3 3

2
1 1

2
1
1

1 1

2 2

1
1

3
3

Stata Output for ANCOVA section, Spring 2006, Page 7 of 8

Simulated Data Set 2

6.

. anova y group /* ignore covariate */


Number of obs =
63
Root MSE
= .492033

R-squared
=
Adj R-squared =

0.7432
0.7347

Source | Partial SS
df
MS
F
Prob > F
-----------+---------------------------------------------------Model | 42.0474144
2 21.0237072
86.84
0.0000
|
group | 42.0474144
2 21.0237072
86.84
0.0000
|
Residual | 14.5257793
60 .242096321
-----------+---------------------------------------------------Total | 56.5731936
62 .912470865
. anova y group x,cont(x) /* include covariate */
Number of obs =
63
Root MSE
= .466398

R-squared
=
Adj R-squared =

0.7731
0.7616

Source | Partial SS
df
MS
F
Prob > F
-----------+---------------------------------------------------Model | 43.7391194
3 14.5797065
67.02
0.0000
|
group | .883631688
2 .441815844
2.03
0.1403
x | 1.69170499
1 1.69170499
7.78
0.0071
|
Residual | 12.8340743
59 .217526682
-----------+---------------------------------------------------Total | 56.5731936
62 .912470865

22

1
1

2 2 2
2
2

3 3

3
3

3
2

2
2

1
1 11
1
1

1 22

3
2

2 2

33 3

1
1

Stata Output for ANCOVA section, Spring 2006, Page 8 of 8

You might also like