Post on 01-May-2015
Disegno del modello di analisi dei dati sperimentali
Lezione 3:
Analisi della varianza (ANOVA)
disegno a blocchi randomizzzati
• Tutti i trattamenti sono assegnati alle stesse unità sperimentali
• trattamenti sono assegnati ”random”
CDC
AAD
DBA
BCB
blocchi (b = 3)
trattamenti (a = 4)
Dy1
trattamenti
paziente
A B C D media
1
2
3
media
Cy1
Ay2
Ay3
Cy2By2 Dy2
By3 Cy3 Dy3
Ay By
1y
2y
3y
Cy Dy y
55443322110 xxxxxy
blocchi (pazienti) trattamenti (Farmaci)
Ay1 By1
trattamenti
paziente
A B C D media
1 5.17 5.21 4.91 4.74 5.008
2 6.23 7.34 6.18 6.31 6.515
3 4.93 4.55 4.64 4.61 4.683
media 5.443 5.700 5.243 5.220 5.402
100101
100011
100001
010101
010011
010001
001101
001011
001001
000101
000011
000001
X
543210 xxxxxx
4.61
6.31
4.74
4.64
6.18
4.91
4.55
7.34
5.21
4.93
6.23
5.17
Ypaziente 3Farm. B
66.15
73.15
10.17
18.73
26.02
64.82
'YX
32
31
31
31
31
32
31
31
31
31
32
31
21
41
41
41
21
41
31
31
31
41
41
21
1
00
00
00
000
000
)'( XX
223.0
2.0
257.0
325.0
507.1
049.5
ˆ
ˆ
ˆ
ˆ
ˆ
ˆ
)'()'(ˆ
5
4
3
2
1
0
1-
YXXX
223.0
2.0
257.0
325.0
507.1
049.5
501.4
333.6
826.4
524.4
357.6
849.4
981.4
813.6
306.5
724.4
557.6
049.5
543210 xxxxxx
100101
100011
100001
010101
010011
010001
001101
001011
001001
000101
000011
000001
ˆˆ XY
Valori Predetti di y
trattamenti
paziente
A B C D media
1 5.17
5.049
5.21
5.306
4.91
4.849
4.74
4.826
5.008
5.008
2 6.23
6.557
7.34
6.813
6.18
6.357
6.31
6.333
6.515
6.515
3 4.93
4.724
4.55
4.981
4.64
4.524
4.61
4.501
4.683
4.683
media 5.443
5.443
5.700
5.700
5.243
5.243
5.220
5.220
5.402
5.402
valore osservato di yvalore predetto di y
4.61
6.31
4.74
4.64
6.18
4.91
4.55
7.34
5.21
4.93
6.23
5.17
Y
109.0
023.0
086.0
0.116
0.177-
0.061
0.431-
0.527
0.096-
0.206
0.327-
0.121
ˆˆ YY
501.4
333.6
826.4
524.4
357.6
849.4
981.4
813.6
306.5
724.4
557.6
049.5
Y
0119.0
0005.0
0074.0
0135.0
0313.0
0037.0
1858.0
2777.0
0092.0
0424.0
1069.0
0146.0
ˆ 2
012
1
i
i 7040.012
1
2 i
i
0.704ˆ Y)(X''βYY'SSE 118.0612
704.02
pn
SSEs 343.0s
Residui e varianza residua
varianze e covarianze
555453525150
454443424140
353433323130
252423222120
151413121110
050403020100
32
31
31
31
31
32
31
31
31
31
32
31
21
41
41
41
21
41
31
31
31
41
41
21
1
00
00
00
000
000
)'(
cccccc
cccccc
cccccc
cccccc
cccccc
cccccc
XX
0585.0)ˆ()ˆ()ˆ( 221
210 sVVV 242.0)ˆ()ˆ()ˆ( 221
210 ssss
0780.0)ˆ()ˆ()ˆ( 232
543 sVVV 280.0)ˆ()ˆ()ˆ( 232
543 ssss
2)ˆ( scV iii
2)ˆ,ˆ( scCov ijji
241
2010 )ˆ,ˆ()ˆ,ˆ( sCovCov 2
31
504030 )ˆ,ˆ()ˆ,ˆ()ˆ,ˆ( sCovCovCov 2
41
21 )ˆ,ˆ( sCov
0)ˆ,ˆ()ˆ,ˆ()ˆ,ˆ()ˆ,ˆ()ˆ,ˆ()ˆ,ˆ( 524232514131 CovCovCovCovCovCov
231
545343 )ˆ,ˆ()ˆ,ˆ()ˆ,ˆ( sCovCovCov
disegno Orthogonale
limiti di confidenza dei parametri al 95%
1))ˆ(ˆ)ˆ(ˆ( ,, iiiii ststP
t0.05,6 = 2.447
95.0)642.5456.4( 0 P
95.0)100.2915.0( 1 P
95.0)268.0918.0( 2 Ppazienti
95.0)941.0428.0( 3 P
95.0)484.0884.0( 4 P
95.0)908.0461.0( 5 P
Farmaci
vi sono differenze tra Farmaci ?Differenza stima varianza
A-B
A-C
A-D
B-C
B-D
C-D
3300ˆ)ˆˆ(ˆ
4400ˆ)ˆˆ(ˆ
5500ˆ)ˆˆ(ˆ
434030ˆˆ)ˆˆ()ˆˆ(
535030ˆˆ)ˆˆ()ˆˆ(
545040ˆˆ)ˆˆ()ˆˆ(
232
3)ˆ( sV
232
4 )ˆ( sV
232
5 )ˆ( sV
232
43 )ˆˆ( sV
2322
312
322
32
434343 2)ˆ,ˆ(2)ˆ()ˆ()ˆˆ( ssssCovVVV
232
53 )ˆˆ( sV
232
54 )ˆˆ( sV
)ˆˆ(
ˆˆ
ji
ji
st
Es: B-D: 716.1
117.0
2233.02567.0
)ˆˆ(
ˆˆ
32
53
536
st
0.1 < P < 0.2
tutte le differenze a coppia
Differenza t P
Pat 1 - Pat 2 6.224 0.0008
Pat 1 – Pat 3 1.342 0.2282
Pat 2 – Pat 3 7.566 0.0003
Farm. A – Farm. B 0.918 0.3942
Farm. A – Farm. C 0.715 0.5014
Farm. A – Farm. D 0.799 0.4550
Farm. B – Farm. C 1.644 0.1536
Farm. B – Farm. D 1.716 0.1369
Farm. C – Farm. D 0.083 0.9362
Perchè i confronti a coppia non sono saggi ?
i confronti a coppia sono non saggi per due ragioni:
(1) Richiedono spesso molte prove
(2) Possono aumentare l'errore del di tipo I di rischio, cioè di rifiuto di H0 anche quando H0 è vera
2stage.exe
Confronti Multipli Se un fattore ha a livelli...Se desideriamo confrontare tutte le differenze possibili tra le medie di s livelli, le prove totali k sono tali che, al paio a, k diventa …
2
)1(
aak
a = 2 k = 1
a = 4 k = 6
a = 10 k = 45
a = 20 k = 190
Se α = 0.05 per singolo test, allora la probabilità di com-mettere almeno un errore di I° tipo (rigettando H0 quando
essa è vera ) si dimostra essere
kP )1(1
1PPProbabilità di errore di I° tipo se k = 1
Probabilità di non errore di I° tipo se k =1
Probabilità di non errore di I° tipo se k > 1 kP )1(
Probabilità di slmeno un errore di tipo I
a = 2 k = 1 P = 0.05
a = 4 k = 6 P = 0.265
a = 10 k = 45 P = 0.901
a = 20 k = 190 P = 0.9999
The Bonferroni adjustment
Se we want that
P(almeno un errore tipo I) ≤ α
allora we need to find α’ so that
1-(1-α’)k ≤ α → α’ ≤ 1 – (1- α)1/k ≈ α/k
errore sperimentale
a = 4 k = 6 α’ ≤ 1 – (1- 0.05)1/6 = 0.00851 α/k = 0.05/6 = 0.00833
a = 10 k = 45 α’ ≤ 1 – (1- 0.05)1/45 = 0.00114 α/k = 0.05/45 = 0.00111
La correzione di Bonferroni è una soluzione d’emergenza al problema di test multipli
A disadvantage della correzione di Bonferroni è che è conservativa, i.e.it accresce il rischio errore di tipo II (accettando H0 quando essa è falsa)
Question 1: sono presenti differenze tra pazienti ?
Question 2: sono presenti differenze tra Farmaci ?
modelo completo :
55443322110 xxxxxy
blocchi trattamenti
La soluzione ”anova” al problema
Risposta alla domanda 1
modelo completo :
55443322110 xxxxxy
Se vi sono no differenze tra persons allora β1, e β2 will both be 0.
H0: Non differenza tra pazienti β1 = β2 = 0
H1: pazienti sono differenti
Se H0 è correct allora
modelo ridotto : 5544330 xxxy
Risposta alla domanda 2
modelo completo :
55443322110 xxxxxy
Se non vi sono differenze tra trattamenti allora β3, β4, e β5 will tutte be 0.
H0: No differenze tra trattamenti β3 = β4 = β5 = 0
H1: trattamenti have an effetto
Se H0 è correct allora
22110 xxymodelo ridotto :
In fine, se nessun trattamento e/o pazienti differisce, abbiamo
modelo completo : 55443322110 xxxxxy
modelo ridotto : 0y
Model 1: 0y df = n-1 =11
Model 2a: 22110 xxy
7988.8)(1
2
n
ii yySSE
1505.1)ˆ(1
2
n
iii yySSE df = n-p = 9
352.8)ˆ(1
2
n
iii yySSE df = n-p = 8Model 2b: 5544330 xxxy
Modello C.: 55443322110 xxxxxy 7040.0SSE df = n-p = 6
Test per gli effetti dei Farmaci
modelo completo :
55443322110 xxxxxy
modelo ridotto : 22110 xxy
150.1)ˆ(1
21
n
iii yySSE
128.0312
150.1
1
121
pn
SSEs
117.0612
704.0
2
222
pn
SSEs
Differenza tra reduced e modelo completo : 446.0213 SSESSESSE
149.036
446.0
12
323
pp
SSEs
704.0)ˆ(1
22
n
iii yySSE
Se H0 è vera , allora s1
2 , s22 and s3
3
will tutte be stime di σ2
Se H0 è not vera , allora s32 > σ2
122
23
s
sF1
22
23
s
sF
Gradi di libertà per F
Since F è the ratio tra s32 con p2-p1 df e s2
2 con n-p2 dfF has p2-p1 df in the numerator e n-p2 df in the denominator, i.e.
22
23
,, 21221 s
sFF pnpp
The F-test è one-tailed (only values larger than 1 leads to rejection ofH0)
MS due to omitting the factor
MS dovuta al modello completo
variazione Spiegata e non Spiegata
variabilità non spiegata per model senza the factor
SSE1
SSE2
variabilità non spiegata per model con the factor
SSE1-SSE2
Explained variation by including the factor
= SS(factor)
df = n-p = 6
Model 1: 0y df = n-1 =11
Model 2a: 22110 xxy
7988.8)(1
2
n
ii yySSE
1505.1)ˆ(1
2
n
iii yySSE df = n-p = 9
Model 2b: 352.8)ˆ(1
2
n
iii yySSE df = n-p = 8 5544330 xxxy
modelo completo : 55443322110 xxxxxy
Test per effetto dei Farmaci
7040.0SSE
variazione Spiegata e non Spiegata per Farmaci
1.151
variazione non Spiegata senza Farmaci
0.704
variazione non Spiegata con Farmaci
variazione non Spiegata by Farmaci
0.447
= SS(Farmaci )
Model 1: 0y df = n-1 =11
Model 2: 22110 xxy
7988.8)(1
2
n
ii yySSE
1505.1)ˆ(1
2
n
iii yySSE df = n-p = 9
Model 2: 352.8)ˆ(1
2
n
iii yySSE df = n-p = 8 5544330 xxxy
modelo completo :
55443322110 xxxxxy 7040.0SSE df = n-p = 6
Test per effetto dei pazienti
variabilità spiegata e non spiegata per pazienti
8.352
variabilità non spiegata senza pazienti
0.704
variabilità non spiegata con pazienti
variabilità spiegata dai pazienti
7.648
= SS(pazienti )
Somma dei quadrati (SS)
variazione Totale =
Variazione dovuta ai pazienti + Variazione dovuta ai Farmaci + variazione non spiegata
variabilità spiegata dal modello
SS (total) = SS (modello) + SS (residual) =
SS (pazienti) + SS (Farmaci) + SSE
Analisi della varianza
Source SS df MS F P
pazienti
Farmaci
Error
SS (pat)
SS (Farmaci )
SSE
b-1
a-1
n-a-b+1
SS(pat)/(b-1)
SS(Farmaci)/(a-1)
SSE/(n-a-b+1)
MS(pat)/s2
MS(FarmacI)/s2
Total SS (total) n-1
Source SS df MS F P
pazienti
Farmaci
Error
SS (pat)
SS (Farmaci )
SSE
b-1
a-1
n-a-b+1
SS(pat)/(b-1)
SS(Farmaci )/(a-1)
SSE/(n-a-b+1)
MS(pat)/s2
MS(Farmaci )/s2
Total SS (total) n-1
Source SS df MS F P
Model 8.095 5 1.619 13.838 0.003
pazienti
Farmaci
Error
7.648
0.447
0.704
2
3
6
3.824
0.149
0.117
32.68
1.27
0.0006
0.366
Total 8.799 11
**
***
Microsoft Excel (2).lnk
Source SS df MS F P
Model 7.648 2 3.824 29.92 0.0001
pazienti
Error
7.648
1.151
2
9
3.824
0.128
29.92 0.0001
Total 8.799 11
***
***
Orthogonal disegno s
32
31
31
31
31
32
31
31
31
31
32
31
21
41
41
41
21
41
31
31
31
41
41
21
1
00
00
00
000
000
)'( XX
241
1010 )ˆ,ˆ()ˆ,ˆ( sCovCov 2
31
504030 )ˆ,ˆ()ˆ,ˆ()ˆ,ˆ( sCovCovCov 2
41
21 )ˆ,ˆ( sCov
0)ˆ,ˆ()ˆ,ˆ()ˆ,ˆ()ˆ,ˆ()ˆ,ˆ()ˆ,ˆ( 524232514131 CovCovCovCovCovCov
231
545343 )ˆ,ˆ()ˆ,ˆ()ˆ,ˆ( sCovCovCov
Disegno Orthogonale
A multifactorial experiment è said to be orthogonal se the stime di the parameters associated con each factor sono independent ofeach other
SS(total) = SS1+SS2+.....+SSk + SSE
An experiment è orthogonal se each level di one factor occurs the same number di times as the number levels di the second factor, e ifthis applies to tutte the factors.
Se an experiment è not orthogonal, allora the parameters will changeeach time a factor è removed from the model, e SS depends on theorder in which factors sono included in the model
How to do it con SAS
DATA eks5_1;
/* eksempel 5.1 i G. Nachman: Forsøgsplanlægning og statistisk
analyse af eksperimentelle data */
/* Programmet udfører en to-sidet variansanalyse med paziente og
behandling som faktorer. disegno et er fuldstændigt faktorielt */
/* Analysen forudsætter, at der ikke er interaktion imellem medikament og paziente */
INPUT pat $ treat $ y; /* indlæser data */
/* pat = paziente (kvalitativ variabel)
treat = behandling (kvalitativ variabel
y = response (kvantitativ variabel) */
CARDS; /* her kommer data. Kan også indlæses fra en fil */
1 A 5.17
2 A 6.23
3 A 4.93
1 B 5.21
2 B 7.34
3 B 4.55
1 C 4.91
2 C 6.18
3 C 4.64
1 D 4.74
2 D 6.31
3 D 4.61
;
PROC GLM; /* procedure General Linear Models */
TITLE 'Eksempel 5.1'; /* medtages hvis der ønskes en titel */
CLASS pat treat; /* pat og treat er klasse (kvalitative) variable */
MODEL y = pat treat / CLM SOLUTION;
/* modellen forudsætter at y afhænger af paziente og behandling */
/* CLM er en option som giver sikkerhedsgrænserne omkring middelværdien
per en given kombination af paziente og behandling */
/* SOLUTION udprinter parameterstimarne */
OUTPUT OUT=new P = pred R= res;
/* OUTPUT laver et nyt datasæt kaldet new. Det indeholder
variablen pred og res, som er de predikterede værdier og
residualerne */
RUN;
Eksempel 5.1 7 13:18 Monday, November 5, 2001 General Linear Models Procedure Class Level Information Class Levels Values PAT 3 1 2 3 TREAT 4 A B C D Number di observations in data set = 12
Eksempel 5.1 8 13:18 Monday, November 5, 2001 General Linear Models Procedure Dependent Variable: Y Source DF Sum di Squares Mean Square F Value Pr > F Model 5 8.09475000 1.61895000 13.80 0.0031 Error 6 0.70401667 0.11733611 Corrected Total 11 8.79876667 R-Square C.V. Root MSE Y Mean 0.919987 6.341443 0.34254359 5.40166667 Source DF tipo I SS Mean Square F Value Pr > F PAT 2 7.64831667 3.82415833 32.59 0.0006TREAT 3 0.44643333 0.14881111 1.27 0.3666 Source DF tipo III SS Mean Square F Value Pr > F PAT 2 7.64831667 3.82415833 32.59 0.0006TREAT 3 0.44643333 0.14881111 1.27 0.3666
Globale significatività di the model
Explained variation
pazienti sono significativamente different
Farmaci sono not significativamente different
T per H0: Pr > |T| Std Error ofParameter stima Parameter=0 stima INTERCEPT 4.500833333 B 18.58 0.0001 0.24221490PAT 1 0.325000000 B 1.34 0.2282 0.24221490 2 1.832500000 B 7.57 0.0003 0.24221490 3 0.000000000 B . . .TREAT A 0.223333333 B 0.80 0.4550 0.27968567 B 0.480000000 B 1.72 0.1369 0.27968567 C 0.023333333 B 0.08 0.9362 0.27968567 D 0.000000000 B . . . NOTE: The X'X matrix has been found to be singular e a generalized inverse was used to solve the normal equations. stime followed by the letter 'B' sono biased, e sono not unique estimators di the parameters.