Você está na página 1de 7

Apndice 1: Programa no proc iml para resolver o Exerccio 15.3.

3
proc iml ;
y = {49,61,55,69,51,38,64,68,70,60,53,59,48,46,59,53,54,48,54,53,37};
x = {35,26,29,32,23,26,31,33,35,28,29,32,23,26,33,36,26,30,33,25,23};
t = {1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3};
k=3;
* nmero de grupos;
n=7;
* nmero de repeties por grupo;
nk=n*k;
* nmero total de observaes;
In = I(n);
Jn = J(n,n,1);
Ink = I(nk);
Jnk = J(nk,nk,1);
Z = J(nk,1,1)||design(t); * calcula a matriz Z;
PZ = Z*ginv(t(Z)*Z)*t(Z); * calcula P = Z(ginv(Z'Z))Z';
*Calcula as somas de quadrados usando (15.25);
exx = t(X)*(Ink-PZ)*X;
exy = t(X)*(Ink-PZ)*y;
eyy = t(y)*(Ink-PZ)*y;
Beta = exy/exx;
* Calcula Beta usando (15.26);
*Calcula a SQ resduo ajustado para a covarivel;
SQRyx = eyy - (exy)**2/exx;
* calcula SQRy.x usando (15.27);
gl_Ryx = k*(n-1)-1;
* calcula gl associado a SQRy.x;
*Calcula a SQ resduo sem o ajuste para a covarivel;
tyy = t(y)*(Ink-Jnk/nk)*y;
* calcula tyy usando (15.34);
txy = t(X)*(Ink-Jnk/nk)*y;
* calcula txy usando (15.34);
txx = t(X)*(Ink-Jnk/nk)*X;
* calcula txx usando (15.34);
SQTyx = tyy - txy**2/txx;
* calcula Ty.x usando (15.33);
gl_Tyx = k*n-2;
* calcula gl associado a Ty.x;
print 'Somas de quadrados importantes',,, exx exy eyy SQRyx gl_Ryx SQTyx gl_Tyx,;
print Beta /;

Somas de quadrados importantes


EXX
EXY
EYY
SQRYX
350.28571 412.71429 1465.7143 979.44529

GL_RYX
SQTYX
17 1141.4709

GL_TYX
19

BETA
1.1782219

*Testando a hiptese H01: alfa1 = alfa2 = alfa3;


SQH01 = SQTyx - SQRyx;
* calcula SQ(alfa|mi,beta) usando (15.30);
gl_H01 = gl_Tyx - gl_Ryx;
* calcula gl associado a SQ(alfa|mi,beta);
F01 = (SQH01/gl_H01)/(SQRyx/gl_Ryx);
* calcula F para testar H01 usando (15.31);
Prob_F01 = 1-probf(F01, gl_H01, gl_Ryx);
* calcula p-valor para F01;
print 'Testando a hiptese H01: alfa1 = alfa2 = alfa3';
print SQH01 gl_H01 F01 Prob_F01;
print SQRyx gl_Ryx /;

Testando a hiptese
SQH01
162.02561

GL_H01
2

SQRYX
979.44529

GL_RYX
17

H01: alfa1 = alfa2 = alfa3


F01 PROB_F01
1.40612 0.2721952

* Testando a hiptese H02: Beta = 0;


SQH02 = exy**2/exx;
* calcula SQH0 usando (15.35);
gl_H02 = 1;
F02 = SQH02/(SQRyx/gl_Ryx);
* calcula estatstica F para testar H02 usando (15.36);
Prob_F02 = 1-probf(F02, gl_H02, gl_Ryx);
* calcula p-valor associado a F02;
print 'Testando a hiptese H02: Beta = 0';
print SQH02 gl_H02 F02 Prob_F02;
print SQRyx gl_Ryx /;

Testando a hiptese H02: Beta = 0


SQH02
486.26899

GL_H02
F02 PROB_F02
1 8.4400558 0.0098538

SQRYX
979.44529

GL_RYX
17

* Testando a hiptese H03: Beta1 = Beta2 = Beta3';


x1=x[1:7,]; x2=x[8:14,]; x3=x[15:21,];
XX = block(x1, x2, x3);
* constri matriz X como definido em (15.39);
Exx = t(XX)*(Ink-PZ)*XX;
* calcula Exx usando (15.41);
exy = t(XX)*(Ink-PZ)*y;
* calcula exy usando (15.43);
Betas = inv(Exx)*Exy;
* calcula os betas usando (15.45);
SQFyx = eyy-t(Exy)*Betas;
* calcula SQR(completo)y.x usando (15.46);
gl_Fyx=k*(n-2);
* calcula gl associado a SQR(completo)y.x;
SQH03 = SQRyx - SQFyx;
* calcula SQH03 usando (15.48);
gl_H03 = gl_Ryx-k*(n-2);
* calcula gl associado a SQH03;
F03 = (SQH03/gl_H03)/(SQFyx/gl_Fyx);
* calcula F associado a H03;
Prob_F03 = 1-probf(F03, gl_H03, gl_Fyx);
* calcula p-valor associado a F03;
print 'Testando a hiptese H03: Beta1 = Beta2 = Beta3';
print SQH03 gl_H03 F03 Prob_F03;
print SQFyx gl_Fyx, ;
print 'Estimativas de Beta1, Beta2 e Beta3', Betas;
quit;

Testando a hiptese H03: Beta1 = Beta2 = Beta3


SQH03
98.855707

GL_H03
F03 PROB_F03
2 0.8419561 0.4502464

SQFYX
880.58959

GL_FYX
15

Estimativas de Beta1, Beta2 e Beta3


BETAS
0.7902778
1.9851351
0.8578629

Apndice 2: Programa no proc glm para resolver o Exerccio 15.3.3


data Ex15_3_3;
input Grupo Rep y x;
cards;
1
1
49
35
1
2
61
26
1
3
55
29
1
4
69
32
1
5
51
23
1
6
38
26
1
7
64
31
2
1
68
33
2
2
70
35
2
3
60
28
2
4
53
29
2
5
59
32
2
6
48
23
2
7
46
26
3
1
59
33
3
2
53
36
3
3
54
26
3
4
48
30
3
5
54
33
3
6
53
25
3
7
37
23
;
proc glm data=Ex15_3_3;
title 'Testa as hipteses H01 e H02';
class Grupo;
model y = grupo x / ss2 solution;
run;

...
Source
Grupo
x
Parameter
...
x

DF
2
1

Type II SS
162.0256063
486.2689932

Estimate
1.17822186

(3)

Mean Square
81.0128031
486.2689932

F Value
1.41
8.44

Standard
Error

t Value

Pr > |t|

0.40555935

2.91

0.0099

Onde:
(1) Traz as informaes do teste da hiptese H01: 1 = 2 = 3
(2) Traz as informaes do teste da hiptese H02: = 0
(3) Traz a estimativa do coeficiente angular
proc glm data=Ex15_3_3;
title 'Testar a hiptese H03';
class Grupo;
model y = grupo grupo*x / solution noint ss2;
contrast 'Betas iguais' grupo*x -2 1 1, grupo*x 0 1 -1;
run;

Pr > F
0.2722
0.0099

(1)
(2)

...
Contrast
Betas iguais
Parameter
...
x*Grupo
1
x*Grupo
2
x*Grupo
3

DF
2
Estimate
0.79027778
1.98513514 (5)
0.85786290

Contrast SS
98.85570672

Mean Square
49.42785336

F Value
0.84

Standard
Error

t Value

Pr > |t|

0.75548164
0.74520250
0.64362711

1.05
2.66
1.33

0.3121
0.0177
0.2025

Pr > F
0.4502

(4) Traz as informaes do teste da hiptese H01: 1 = 2 = 3


(5) Traz as estimativas dos coeficientes angulares associados aos trs grupos.

(4)

Apndice 3: Programa no proc iml para resolver o Exerccio 15.4.1


data Ex15_4_1;
input C A Rep y x;
cards;
1
1
1
6399
1
1
2
8456
1
1
3
8453
1
1
4
4891
1
1
5
3491
1
2
1
6944
1
2
2
6971
1
2
3
4053
1
2
4
8767
1
2
5
6765
2
1
1
2490
2
1
2
5349
2
1
3
5518
2
1
4 10417
2
1
5
4278
2
2
1
4936
2
2
2
7376
2
2
3
6216
2
2
4 10313
2
2
5
5124
3
1
1
4489
3
1
2 10026
3
1
3
5659
3
1
4
5475
3
1
5 11382
3
2
1
5731
3
2
2
6787
3
2
3
5814
3
2
4
9607
3
2
5
9817
;

160
320
200
160
120
160
160
120
280
160
90
154
160
234
120
160
200
160
240
120
120
245
160
160
320
160
173
134
239
320

proc glm;
title 'Testa as hiptese H01 e H02';
class A C;
model y = A C A*C x / ss3 solution noint;
run;

Testa as hiptese H01 e H02


The GLM Procedure
Dependent Variable: y
Source
Model
Error
Uncorrected Total
R-Square
0.809448
Source
A
C
A*C
x

Coeff Var
16.64051

DF
7
23
30

Sum of
Squares
1482703140
28873230
1511576370

Root MSE
1120.428
DF
1
2
2
1

Mean Square
211814734
1255358

F Value
168.73

Pr > F
<.0001

F Value
1.10
0.31
0.37
87.57

Pr > F
0.3061
0.7398
0.6938
<.0001

y Mean
6733.133

Type III SS
1375355.1
766750.1
932749.5
109932635.1

Mean Square
1375355.1
383375.0
466374.8
109932635.1

(1)
(2)
(3)
(4)

Parameter
...
x

Estimate
32.0726921

(5)

Standard
Error

t Value

Pr > |t|

3.427330

9.36

<.0001

(1) Traz as informaes do teste da hiptese H01: 1 = 2 (fator A)


(2) Traz as informaes do teste da hiptese H01: 1 = 2 (fator C)
(3) Traz as informaes do teste da hiptese H01: 11 = 12 = 21 = 22 (interao AC)
(4) Traz as informaes do teste da hiptese H02: = 0.
(5) Traz a estimativa do coeficiente angular

* Fator A: compara os Betas;


proc glm;
title 'Fator A: Testa H03';
class A C;
model y = A C A*C x(A)/ ss1 solution noint;
contrast 'Fator A: Betas iguais' x(A) 1 -1;
run;

...
Contrast
Fator A: Betas iguais
Parameter
...
x(A)
1
x(A)
2

DF
1

Contrast SS
1157140.937

Estimate
34.906580
28.251949

(7)
(7)

Mean Square
1157140.937

F Value
0.92

Standard
Error

t Value

Pr > |t|

4.531216
5.261352

7.70
5.37

<.0001
<.0001

Pr > F
0.3483

(6)

(6) Traz as informaes do teste da hiptese de homogeneidade dos coeficientes nagulares para o fator A.
(7) Traz as estimativas dos coeficientes dos coeficientes angulares (fator A).

* Fator C: compara os Betas;


proc glm;
title 'Fator C: Testa H03';
class A C;
model y = A C A*C x(C)/ ss1 solution noint;
contrast 'Fator C: Betas iguais' x(C) 2 -1 -1, x(C) 0 1 -1;
run;
...
Contrast
Fator C: Betas iguais

DF
2

Contrast SS
9506034.164

Mean Square
4753017.082

F Value
5.15

Pr > F
0.0151

(8)

Parameter
...
x(C)
1
x(C)
2
x(C)
3

Estimate
23.210417
50.085129 (9)
31.669261

Standard
Error

t Value

Pr > |t|

4.900700
6.794143
4.361080

4.74
7.37
7.26

0.0001
<.0001
<.0001

(8) Traz as informaes do teste da hiptese de homogeneidade dos coeficientes nagulares para o fator C.
(9) Traz as estimativas dos coeficientes dos coeficientes angulares (fator C).

Você também pode gostar