20.06.2013 Views

Dispensa di modelli lineari in R - Dipartimento di Statistica

Dispensa di modelli lineari in R - Dipartimento di Statistica

Dispensa di modelli lineari in R - Dipartimento di Statistica

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CAPITOLO 11. ANALISI DELLA COVARIANZA 119<br />

Per verificare l’ipotesi prima formulata, si dovrebbe effettuare un confronto tra il<br />

peso me<strong>di</strong>o del cuore <strong>di</strong> maschi e femm<strong>in</strong>e al netto del peso del corpo. L’analisi<br />

della covarianza consente <strong>di</strong> sviluppare tale confronto.<br />

A tal f<strong>in</strong>e, si <strong>in</strong><strong>di</strong>ch<strong>in</strong>o con (yi, xi, zi), i = 1, . . . , 48, le 48 terne <strong>di</strong> valori contenenti<br />

nell’or<strong>di</strong>ne, per ciascuna unità statistica, il peso del cuore, il peso del corpo e l’<strong>in</strong><strong>di</strong>catore<br />

del sesso. Si supponga che la variabile <strong>in</strong><strong>di</strong>catrice zi, che co<strong>di</strong>fica il sesso,<br />

assuma il valore 0 per le femm<strong>in</strong>e e 1 per i maschi. Si assuma che y1, . . . , y48 siano<br />

realizzazioni <strong>di</strong> v.c. <strong>in</strong><strong>di</strong>pendenti Yi tali che<br />

Yi = β1 + β2 xi + β3 zi + β4 xi zi + εi<br />

con εi ∼ N(0, σ 2 ) <strong>in</strong><strong>di</strong>pendenti, i = 1, . . . , 48. Tale modello prevede per i =<br />

1, . . . , 24, ossia per il sesso femm<strong>in</strong>ile, Yi ∼ N(β1 + β2 xi, σ 2 ), mentre per i =<br />

25, . . . , 48, ossia per il sesso maschile, Yi ∼ N((β1 + β3) + (β2 + β4) xi, σ 2 ).<br />

L’ipotesi nulla <strong>di</strong> uguaglianza del peso me<strong>di</strong>o del cuore nei due sessi al netto dell’effetto<br />

del peso del corpo corrisponde all’ipotesi statistica<br />

H0: β3 = β4 = 0<br />

H1:<br />

¯ H0<br />

La verifica <strong>di</strong> tale ipotesi può essere condotta utilizzando le funzioni lm() e anova().<br />

Prima <strong>di</strong> procedere, si controlli come R ha co<strong>di</strong>ficato il fattore sesso.<br />

> contrasts(sesso)<br />

M<br />

F 0<br />

M 1<br />

Dunque, viene associato il valore 1 alla modalità M e 0 alla modalità F. La co<strong>di</strong>fica<br />

effettuata da R co<strong>in</strong>cide qu<strong>in</strong><strong>di</strong> con la def<strong>in</strong>izione della variabile zi utilizzata nel<br />

modello statistico sopra def<strong>in</strong>ito. Il modello viene adattato con<br />

> gatti.lm gatti.lm summary(gatti.lm)<br />

Call:<br />

lm(formula = pcuore ~ pcorpo + sesso + pcorpo:sesso)<br />

Residuals:<br />

M<strong>in</strong> 1Q Me<strong>di</strong>an 3Q Max<br />

-1.981 -0.959 -0.163 0.857 2.628

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!