Disegno del modello di analisi dei dati sperimentali Lezione 2 interpolare un modello ai dati e valutare i relativi parametri
(-2,16) (-1,7) (0,4)(1,6) (2,10) dove x 1 = x ed x 2 = x 1 2
(-2,16) (-1,7) (0,4)(1,6) (2,10) dove x 1 = x ed x 2 = x 1 2 ε i è il residuo per la i-ma osservazione
Il modello migliore interpolante è un modello che minimizza la somma delle deviazioni quadrate fra il i valori osservati ed i valori predetti dal modello, i.e.
Come fare i calcoli dove x 1 = x ed x 2 = x 1 2 (x,y) = (-2,16) => y = β 0 (1) + β 1 (-2) + β 2 (4) + ε = 16 (x,y) = (-1,7) => y = β 0 (1) + β 1 (-1) + β 2 (1) + ε = 7 (x,y) = (0,4) => y = β 0 (1) + β 1 (0) + β 2 (0) + ε = 4 (x,y) = (1,6) => y = β 0 (1) + β 1 (1) + β 2 (1) + ε = 6 (x,y) = (2,10) => y = β 0 (1) + β 1 (2) + β 2 (4) + ε = 10 x 0 x 1 x 2 y
Matrice X Transposta
Matrice Inversa di XX
(XX) -1 è called il inverse matrix di XX. It è defined as
Matrice di Varianza - Covarianza
stima della varianza residua (s 2 ) Somma degli scarti quadratici gradi di libertà per s 2
Varianza dei parametri stimati Matrice di Varianza - Covarianza:
Covarianza dei parametri stimati Matrice di Varianza - Covarianza
limiti di confidenza per β i
Varianza della retta predetta Assumiamo che si voglia to predire y per un assegnato valore di x Il valore scelto di x è chiamato a Possiamo ora scrivere l'equazione come:
Ex. a = -4 nota! dovrebbe essere -1.3
V(x+y) = V(x) + V(y) + 2Cov(x,y) V(x-y) = V(x) + V(y) – 2Cov(x,y) V(ax) = a 2 V(x) Cov(ax,by) = abCov(x,y) Una via alternativa del calcolo
La varianza di una nuova osservazione di y a = -4 V(y) = ( )0.829 = SE(y) = 3.73 Varianza della retta Varianza di nuova oss
limiti di confidenza 95% limiti di confidenza limiti di confidenza per la retta: a = -4 95% limiti di confidenza per singole osservazioni:
limiti di confidenza al 95%
come fare questo in SAS?
DATA eks21; INPUT x y; CARDS; ; PROC GLM; MODEL y = x x*x/solution ; OUTPUT out= new p= yhat L95M= low_mean U95M = up_mean L95 = low U95 = upper; RUN; PROC PRINT; RUN;
Number di observations in data set = 5 General Linear Models Procedure Dependent Variable: Y Source DF Sum di Squares Mean Square F Value Pr > F Model Error Corrected Total R-Square C.V. Root MSE Y Mean Source DF Type I SS Mean Square F Value Pr > F X X*X Source DF Type III SS Mean Square F Value Pr > F X X*X T per H0: Pr > |T| Std Error of Parameter Estimate Parameter=0 Estimate INTERCEPT X X*X OBS X Y YHAT LOW_MEAN UP_MEAN LOW UPPER s2s2 s
DATA eks21; INPUT x y; CARDS; ; PROC GLM; MODEL y = x x*x/solution ; OUTPUT out= new p= yhat L95M= low_mean U95M = up_mean L95 = low U95 = upper; RUN; PROC PRINT; RUN;
OBS X Y YHAT LOW_MEAN UP_MEAN LOW UPPER
Un problema più complesso Interpola con un modello questi dati
DATA polynom; INPUT x y; CARDS; ; DATA add; SET polynom; x2 = x**2; x3 = x**3; x4 = x**4; PROC REG; MODEL y = x x2 x3 x4; RUN;
il SAS System 08:22 Tuesday, October 29, il REG Procedure Model: MODEL1 Dependent Variable: y Analysis di Varianza Sum di Mean Source DF Squares Square F Value Pr > F Model <.0001 Error Corrected Total Root MSE R-Square Dependent Mean Adj R-Sq Coeff Var Parameter Estimates Parameter Standard Variable DF Estimate Error t Value Pr > |t| Intercept x x x x polinomio di quarto ordine
il SAS System 08:22 Tuesday, October 29, Procedure REG Model: MODEL1 Dependent Variable: y Analysis di Varianza Sum di Mean Source DF Squares Square F Value Pr > F Model <.0001 Error Corrected Total Root MSE R-Square Dependent Mean Adj R-Sq Coeff Var Parameter Estimates Parameter Standard Variable DF Estimate Error t Value Pr > |t| Intercept x x x polinomio di terzo ordine
The SAS System 08:22 Tuesday, October 29, il REG Procedure Model: MODEL1 Dependent Variable: y Analysis di Varianza Sum di Mean Source DF Squares Square F Value Pr > F Model <.0001 Error Corrected Total Root MSE R-Square Dependent Mean Adj R-Sq Coeff Var Parameter Estimates Parameter Standard Variable DF Estimate Error t Value Pr > |t| Intercept x x polinomio di secondo ordine
The SAS System 08:22 Tuesday, October 29, il REG Procedure Model: MODEL1 Dependent Variable: y Analysis di Varianza Sum di Mean Source DF Squares Square F Value Pr > F Model Error Corrected Total Root MSE R-Square Dependent Mean Adj R-Sq Coeff Var Parameter Estimates Parameter Standard Variable DF Estimate Error t Value Pr > |t| Intercept x polinomio di primo ordine (una retta)
True relationship: y = x – 0.02x x 3 + ε ε è normally distributed with 0 mean ed σ = 10 Estimated relationship: y = – 1.415x x 2 s = Estimated relationship: y = x s = This è a better fit than this
Notazioni Matriciali Of particular interest to us è il fact that not even in regression analysis was much use made di matrix algebra. In fact one di us, as a statistics graduate student at Cambridge University in il early 1950s, had lectures on multiple regression that were couched in scalar notation! This absence di matrices ed vectors è surely surprising when one thinks di A.C. Aitken. His two books, Matrices ed Determinants ed Statistical Mathematics were both first published in 1939, had fourth ed fifth editions, respectively, in 1947 ed 1948, ed are still in print. Yet, very surprisingly, il latter makes no use di matrices ed vectors which are so thoroughly dealt with in il former. There were exceptions, di course, as have already been noted, such as Kempthorne (1952) ed his co-workers, e.g. Wilk ed Kempthorne (1955, 1956) – ed others, too. Even with matrix expressions available, arithmetic was a real problem. A regression analysis in il New Zealand Department di Agriculture in il mid-1950s involved 40 regressors. Using electromechanical calculators, two calculators (people) using row echelon methods needed six weeks to invert il 40 x 40 matrix. One person could do a row, then il other checked it (to a maximum capacity di 8 to 10 digits, hoping per 4- or 5-digit accuracy in il final result). That person did il next row ed passed it to il first person per checking; ed so on. This was il impasse: matrix algebra was appropriate ed not really difficult. But il arithmetic stemming therefrom could be a nightmare. (From Linear Models by Shayle R. Searle ed Charles E. McCulloch in Advances in Biometry (eds. Peter Armitage ed Herbert A. David), John Wiley & Sons, 1996)