scieee AI-readable full text Open interactive document viewer

Unit 3: Statistical modeling. The general linear model (part II)

Montero Mercadé, Lídia

Full text

2020-2021 Academic year SIM course. Master in Data Science – FIBUPC LECTURE NOTES: UNIT 3-2 - Statistical Modeling (II) – The General Linear Model SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-2 2021-2022 Academic year CONTENTS 3.2-1. READING LIST _______________________________________________________________________________ 3 3.2-2. INTRODUCTION TO THE GENERAL LINEAR MODEL ___________________________________________ 4 3.2-3. ONE-WAY ANOVA ____________________________________________________________________________ 7 3.2-3.1 EXAMPLE: PRESTIGE OF CANADIAN OCCUPATIONS IN DATA.FRAME PRESTIGE IN CAR LIBRARY FOR R (FOX AND WEISBERG 2011) ____________________________________________________________________________________ 15 3.2-4. TWO-WAY ANOVA __________________________________________________________________________ 20 3.2-4.1 EXAMPLE: PRESTIGE OF CANADIAN OCCUPATIONS VS TYPE AND FEMALE FACTOR (FOX AND WEISBERG 2011)____ 29 3.2-5. MORE COMPLEX ANOVA MODELS ___________________________________________________________ 35 3.2-6. ANALYSIS OF COVARIANCE (ANCOVA MODELS) _____________________________________________ 36 3.2-7. ANALYSIS OF COVARIANCE (ANCOVA MODELS) _____________________________________________ 41 3.2-7.1 MANUAL EXAMPLE: TRAINING TYPE FOR RUNNERS (DOBSON 1990) ______________________________________ 41 3.2-7.2 EXAMPLE: PRESTIGE OF CANADIAN OCCUPATIONS IN DATA.FRAME PRESTIGE IN CAR LIBRARY FOR R (FOX AND WEISBERG 2011) ____________________________________________________________________________________ 44 SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-3 2021-2022 Academic year 3.2-1 READING LIST Basic references:  Fox, J. Applied Regression Analysis and Generalized Linear Models. Sage Publications, 2nd Edition 2008.  Fox and Weisberg. An R Companion to Applied Regression. Sage Publications, 2nd Edition 2010. SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-4 2021-2022 Academic year 3.2-2 INTRODUCTION TO THE GENERAL LINEAR MODEL Let ( ) n Tyy ,,y  1 = be a vector of n observations, randomly drawn from the vector ( ) n TYY ,,Y  1 = , whose variables are statistically independent and distributed with expectation ( ) n T µµ ,, 1= µ : In linear models, the random component ( ) n T YY ,,Y  1 = is assumed to be normally distributed 𝑌𝑌 𝑖𝑖|𝑋𝑋𝑖𝑖~𝑁𝑁(𝜇𝜇𝑖𝑖,𝜎𝜎) with constant variance 2 σ , 𝑉𝑉(𝑌𝑌 𝑖𝑖|𝑋𝑋𝑖𝑖)=𝜎𝜎2 and expectation 𝐸𝐸(𝑌𝑌 𝑖𝑖|𝑋𝑋𝑖𝑖)=𝜇𝜇𝑖𝑖 Therefore, the response variable is modeled as normally distributed; thus, negative or positive values, which may be arbitrarily small or large, may be encountered as data for the response and prediction. The systematic component of the model consists in specifying a vector called the linear predictor, denoted η , of the same length as the response, dimension n. In vector notation, the parameters are ( ) p T ββ ,, 1 = β and the regressors are ( ) p XX ,, 1=X and, thus, βη X= where η is nx1, X is nxp and β is px1. Now, we will learn how to include factors as explanatory variables in the model. Vector µ is the direct linear predictor η ; therefore, the link function is µη = or 𝜇𝜇𝑖𝑖=𝑋𝑋𝑖𝑖𝛽𝛽 SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-5 2021-2022 Academic year 3.2-2. INTRODUCTION TO THE GENERAL LINEAR MODEL The general linear model is an extension of multiple regression models to deal with explanatory variables as factors (nominal or qualitative variables) and the interaction between covariates (numeric variables) and factors. Linear regression can be extended to accommodate categorical variables (factors) using dummy variables (or indicator variables). ANOVA models can have one, two or more factors in the linear predictor, leading to one-way ANOVA, two-way ANOVA and general ANOVA. When factors produce additive effects of the first order, second order etc., interaction effects may appear. ANCOVA models combine factors (either main effects and/or interactions), covariates and interactions between factors (groups of factors) and covariates. We are going to see: 1. One-way ANOVA: One factor and main effects only. 2. Two-way ANOVA: Main effects and interaction effects occur. 3. K Way ANOVA: Extension to multiple factors and high-order interactions. 4. ANCOVA models: One factor and one covariate. 5. Extension to multiple factors, covariates and interactions: the general linear model. SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-6 2021-2022 Academic year 3.2-2. INTRODUCTION TO THE GENERAL LINEAR MODEL • General linear models are estimated by least squares estimation. • Model validation can be assessed using standard techniques of residual analysis. Unusual and influential data can be detected using standard techniques. • Be careful when interpreting t-tests in ordinary output tables for regression. • Interpretation and inference can be misleading when there are high-order interactions. • It doesn’t make much sense to standardize dummy variables: o They cannot be increased by standard deviation, so the regular interpretation for standardized coefficients does not apply. o Moreover, the standard interpretation of dummy variables showing differences in level between two categories is lost. o We cannot standardize interaction effects; they are dependent on the main effects. o We can, however, standardize quantitative variables beforehand and construct interaction terms afterwards. SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-7 2021-2022 Academic year 3.2-3 ONE-WAY ANOVA • Does height depend on gender? • Does profession prestige in the Duncan data depend on the type of profession? Both height and prestige are numeric response data and we can assume there is a first random component stated as normal leading to an OLS estimator. • Gender is a dichotomous factor (two levels: male or female). • Type of profession is a polytomous factor, consisting of three levels: “blue collar” “white collar” and “professional”. How do we interpret the R2 ? Just as we did in multiple regression: • A high R2 means that the regressors explain the variation in Y. • A high R2 does not mean that you have eliminated omitted-variable bias. • A high R2 does not mean that the variables included are statistically significant; this must be determined using hypothesis tests. SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-8 2021-2022 Academic year 3.2-3. ONE-WAY ANOVA The ANOVA model for one factor (usually with I level) - Grasping the basic concepts: • Formulation and construction of the design matrix for the models of regression. • Interpretation of its parameters. • Discussion of inference. Group 1 1 11211 ,,, n yyy  Mean 1 y Group 2 2 22221 ,,, n yyy  Mean 2 y ... ... ... Group I I InII yyy ,,, 21  Mean I y (1) ijiij Y εµ += , I parameters () I0N 2 , σ n ≈ ε . (2) ijiij Y εαµ ++= , µ is the overall expected mean and i α effect for i level, I+1 parameters. The usual null hypothesis is that there are no differences between the expected mean of the groups, which can be written according to the formulas as: (1) µµµ === I  1 : 0 H versus : 1 H µµ =∃ i . (2) 0 :1=== I αα  0 H versus 0: ≠∃ i α 1 H . SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-9 2021-2022 Academic year 3.2-3. ONE-WAY ANOVA To simplify, assume without loss of generality that group sizes are equal to J, Ii Jni,,1 == Formula (1) ijiij Y εµ +=                                  −      = IJ I J y y y y I     1 1 11 _ 1 Y ,   { {                 = 1000 0 01 0 001 X I 2 1      ,           = I µ µ  1 β ,                                  −      = IJ I J ε ε ε ε    1 1 11 _ ε Therefore, the estimator of the parameters is the average of the groups, assuming the number of replies per class is identical and equal to (J). The disadvantage of this formulation is that it cannot be easily extended to more than one factor and therefore the ANOVA formula (2) is generally used. ( )           =                       == ∑ ∑ = = − − I J jIj J jj y y y y J J  1 1 11 1 0 0 YXXXb T 1 T SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-16 2021-2022 Academic year 3.2-3. ONE-WAY ANOVA: EXAMPLE First of all, a summary of the data: there are 4 missing values in factor - type  The default R plot to inspect the relation between a numeric variable (prestige) and a factor (type) works well: > plot(prestige~type, main="prestige vs type",col=3) > summary(Prestige) education income women prestige census type Min. : 6.380 Min. : 611 Min. : 0.000 Min. :14.80 Min. :1113 bc :44 1st Qu.: 8.445 1st Qu.: 4106 1st Qu.: 3.592 1st Qu.:35.23 1st Qu.:3120 prof:31 Median :10.540 Median : 5930 Median :13.600 Median :43.60 Median :5135 wc :23 Mean :10.738 Mean : 6798 Mean :28.979 Mean :46.83 Mean :5402 NA's: 4 3rd Qu.:12.648 3rd Qu.: 8187 3rd Qu.:52.203 3rd Qu.:59.27 3rd Qu.:8312 Max. :15.970 Max. :25879 Max. :97.510 Max. :87.20 Max. :9517 > plot(prestige~type) SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-17 2021-2022 Academic year 3.2-3. ONE-WAY ANOVA: EXAMPLE • Descriptive statistics of groups and standard procedure for one-way ANOVA: > tapply(prestige,type,summary) $bc Min. 1st Qu. Median Mean 3rd Qu. Max. 17.30 27.10 35.90 35.53 42.60 54.90 $prof Min. 1st Qu. Median Mean 3rd Qu. Max. 53.80 61.00 68.40 67.85 72.95 87.20 $wc Min. 1st Qu. Median Mean 3rd Qu. Max. 26.50 35.90 41.50 42.24 47.50 67.50 > oneway.test(prestige~type) One-way analysis of means (not assuming equal variances) F = 117.2471, num df = 2.000, denom df = 54.979, p-value < 2.2e-16 > oneway.test(prestige~type,var=TRUE)# Corresponds to F-Test One-way analysis of means F = 109.5916, num df = 2, denom df = 95, p-value < 2.2e-16 > kruskal.test(prestige~type)# Non Parametric version for One-way means test Kruskal-Wallis rank sum test Kruskal-Wallis chi-squared = 63.3965, df = 2, p-value = 1.713e-14 SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-18 2021-2022 Academic year 3.2-3. ONE-WAY ANOVA: EXAMPLE > model<-lm(prestige~type, data=Prestige[!is.na(Prestige$type),], + contrasts=list(type="contr.treatment")) > summary(model) Call: lm(formula = prestige ~ type, data = Prestige[!is.na(Prestige$type), ], contrasts = list(type = "contr.treatment")) Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 35.527 1.432 24.810 < 2e-16 *** typeprof 32.321 2.227 14.511 < 2e-16 *** typewc 6.716 2.444 2.748 0.00718 ** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 9.499 on 95 degrees of freedom Multiple R-squared: 0.6976, Adjusted R-squared: 0.6913 F-statistic: 109.6 on 2 and 95 DF, p-value: < 2.2e-16 244.42716 .6527.35 ˆ ˆˆ 848.67321. 32527.35 ˆ ˆˆ 527.350527.35 ˆ ˆˆ 3 2 1 ˆ ˆˆ 333 222 111 0 ˆ 1 =+=+== =+=+== =+=+== ≡= ≡= ≡= →+= = αµ αµ α µ αµ α yy yy yy wc i profi bci y j j j iij  SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-19 2021-2022 Academic year 3.2-3. ONE-WAY ANOVA: EXAMPLE > model<-lm(prestige~type, data=Prestige[!is.na(Prestige$type),], + contrasts=list(type="contr.sum")) > summary(model) Call: lm(formula = prestige ~ type, data = Prestige[!is.na(Prestige$type), ], contrasts = list(type = "contr.sum")) Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 48.5397 0.9935 48.86 <2e-16 *** type1 -13.0124 1.2925 -10.07 <2e-16 *** type2 19.3087 1.3990 13.80 <2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 9.499 on 95 degrees of freedom Multiple R-squared: 0.6976, Adjusted R-squared: 0.6913 F-statistic: 109.6 on 2 and 95 DF, p-value: < 2.2e-16 ( ) 244.42309.19013.13540.48 ˆ ˆˆ 849.67309.19540.48 ˆ ˆˆ 527.35013.13540.48 ˆ ˆˆ 3 2 1 ˆ ˆˆ 333 222 111 0 ˆˆˆ 321 =−+=+== =+=+== =−=+== ≡= ≡= ≡= →+= =++ αµ αµ αµ αµ ααα yy yy yy wci profi bci y j j j iij  SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-20 2021-2022 Academic year 3.2-4 TWO-WAY ANOVA Motivation: Prestige of professions (Y response) is related to profession type (factor A) and a new factor indicating whether they are mostly female professions (percentage of women greater than 50%) (factor B)? > plot.design(prestige~type+f.femenin) > summary(Prestige) education income women prestige census type f.femenin Min. : 6.380 Min. : 611 Min. : 0.000 Min. :14.80 Min. :1113 bc :44 No :75 1st Qu.: 8.445 1st Qu.: 4106 1st Qu.: 3.592 1st Qu.:35.23 1st Qu.:3120 prof:31 Yes:27 Median :10.540 Median : 5930 Median :13.600 Median :43.60 Median :5135 wc :23 Mean :10.738 Mean : 6798 Mean :28.979 Mean :46.83 Mean :5402 NA's: 4 3rd Qu.:12.648 3rd Qu.: 8187 3rd Qu.:52.203 3rd Qu.:59.27 3rd Qu.:8312 Max. :15.970 Max. :25879 Max. :97.510 Max. :87.20 Max. :9517 > plot(prestige~type*f.femenin) SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-21 2021-2022 Academic year 3.2-4. TWO-WAY ANOVA The analysis of variance of two factors examines the relationship between a quantitative response variable and two explanatory qualitative variables. The inclusion of the second factor allows the modeling and standardization of dependence relations and the inclusion of interactions. Assuming in a two-way ANOVA that population means for each cell in the combinations of the levels of the factor patterns of usual relationships appear clearly. 1 .... J 1 11 µ .... J 1 µ •1 µ      I 1I µ .... IJ µ •I µ 1• µ .. .. J• µ If factors A and B do not interact, then the partial relationship between each factor and the response variable does not depend on the level of the other factor, that is, the difference between levels is constant. Assume I = 4 and J = 2 in the following diagrams. A SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-22 2021-2022 Academic year 3.2-4. TWO-WAY ANOVA 1 2 543210 8 7 6 5 4 3 FACTOR A mu_ij FACTOR B Factors A and B are significant. There are no interactions between factors A and B. Factor A is significant. Factor B is not significant. There are no interactions between factors A and B. 1 2 0 1 2 3 4 5 3 4 5 6 7 8 mu_ij FACTOR A FACTOR B SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-23 2021-2022 Academic year 3.2-4. TWO-WAY ANOVA Factor A is not significant. Factor B is significant. There are no interactions between factors A and B. Factors A and B are significant. There are interactions between factors A and B. 1 2 1 2 3 4 2 3 4 5 6 mu_ij FACTOR A FACTOR B 1 2 54 3 21 0 8 7 6 5 4 3 mu_ij FACTOR A FACTOR B SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-24 2021-2022 Academic year 3.2-4. TWO-WAY ANOVA Two-way ANOVA models (M 0) Null model: ijkijk Y εµ += (M 1) Two-way ANOVA with interactions: ijkij ji ijk Y εγ β αµ ++ + += (M 2) Additive two-way ANOVA: ijk ji ijk Y ε βαµ +++= (M 3) One-way ANOVA of A: ijki ijk Y εαµ ++= (M 4) One-way ANOVA of B: ijk jijk Y εβµ ++= Most common hypothesis tested in two-way ANOVA: only RSS for models needed. • H1: There are no interactions between the two factors. F-test : H: Model (M1) and (M2) are equivalent >anova(m2,m1) • H2: Net effect of factor A once factor B is included in the model (or factor B | A) is not significant. F-test : H: Model (M4) and (M2) are equivalent >anova(m4,m2) F-test : H: Model (M3) and (M2) are equivalent >anova(m3,m2) (for factor B | A) SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-25 2021-2022 Academic year 3.2-4. TWO-WAY ANOVA • H3: Gross effect of factor A (or factor B). F-test : H: Model (M0) and (M3) are equivalent >anova(m0,m3) F-test : H: Model (M0) and (M4) are equivalent >anova(m0,m4) SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-32 2021-2022 Academic year 3.2-4. TWO-WAY ANOVA > summary(m2) Call: lm(formula = prestige ~ type + f.femenin,data=Prestige[!is.na(Prestige$type),]) Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 36.068 1.471 24.516 < 2e-16 *** typeprof 32.438 2.216 14.640 < 2e-16 *** typewc 8.096 2.608 3.104 0.00252 ** f.femeninYes -3.398 2.333 -1.456 0.14869 Residual standard error: 9.443 on 94 degrees of freedom Multiple R-squared: 0.7043, Adjusted R-squared: 0.6949 F-statistic: 74.63 on 3 and 94 DF, p-value: < 2.2e-16 > SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-33 2021-2022 Academic year 3.2-4. TWO-WAY ANOVA > options(contrasts=c("contr.sum","contr.sum")) > m2<-lm(prestige~type+f.femenin,data=Prestige[!is.na(Prestige$type),]) > summary(m2) Call:lm(formula = prestige ~ type + f.femenin,data=Prestige[!is.na(Prestige$type),]) Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 47.880 1.087 44.066 <2e-16 *** type1 -13.511 1.330 -10.160 <2e-16 *** type2 18.927 1.415 13.372 <2e-16 *** f.femenin1 1.699 1.167 1.456 0.149 --- Residual standard error: 9.443 on 94 degrees of freedom Multiple R-squared: 0.7043, Adjusted R-squared: 0.6949 F-statistic: 74.63 on 3 and 94 DF, p-value: < 2.2e-16> SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-34 2021-2022 Academic year 3.2-4. TWO-WAY ANOVA > options(contrasts=c("contr.sum","contr.sum")) > m1<-lm(prestige~type*f.femenin,data=Prestige[!is.na(Prestige$type),]) > summary(m1) Call:lm(formula = prestige ~ type * f.femenin, data = Prestige[!is.na(Prestige$type),]) Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 47.2736 1.1702 40.397 < 2e-16 *** type1 -13.2458 1.6219 -8.167 1.62e-12 *** type2 18.3398 1.7039 10.763 < 2e-16 *** f.femenin1 1.7854 1.1702 1.526 0.131 type1:f.femenin1 0.4138 1.6219 0.255 0.799 type2:f.femenin1 1.8612 1.7039 1.092 0.278 --- Residual standard error: 9.438 on 92 degrees of freedom Multiple R-squared: 0.7109, Adjusted R-squared: 0.6952 F-statistic: 45.25 on 5 and 92 DF, p-value: < 2.2e-16 𝑌𝑌 𝑖𝑖𝑗𝑗 =𝜇𝜇+𝛼𝛼𝑖𝑖+𝛽𝛽𝑗𝑗+𝛾𝛾𝑖𝑖𝑗𝑗 𝑤𝑤𝑤𝑤𝑤𝑤ℎ 𝛼𝛼1+𝛼𝛼2+𝛼𝛼3= 0, 𝛽𝛽1+𝛽𝛽2= 0, 𝛾𝛾1𝑗𝑗 +𝛾𝛾2𝑗𝑗 +𝛾𝛾3𝑗𝑗 = 0 𝑎𝑎𝑛𝑛𝑛𝑛 𝛾𝛾𝑖𝑖1 +𝛾𝛾𝑖𝑖2 = 0 i=1 and j=1: 𝑌𝑌 11 =𝜇𝜇+𝛼𝛼1+𝛽𝛽1+𝛾𝛾11 = 47.27 -13.25 +1.79 +0.41 = 36.22 i=2 and j=1: 𝑌𝑌 21 =𝜇𝜇+𝛼𝛼2+𝛽𝛽1+𝛾𝛾21 = 47.27 +18.34 +1.79 +1.86 i=3 and j=1: 𝑌𝑌 31 =𝜇𝜇+𝛼𝛼3+𝛽𝛽1+𝛾𝛾31 = 47.27 +13.25-18.24 +1.79 –0.41-1.86 i=1 and j=2: 𝑌𝑌 12 =𝜇𝜇+𝛼𝛼1+𝛽𝛽2+𝛾𝛾12 = 47.27 -13.25 -1.79 -0.41 i=2 and j=2: 𝑌𝑌 22 =𝜇𝜇+𝛼𝛼2+𝛽𝛽2+𝛾𝛾22 = 47.27 +18.34 -1.79 -1.86 i=3 and j=2: 𝑌𝑌 32 =𝜇𝜇+𝛼𝛼3+𝛽𝛽2+𝛾𝛾32 = 47.27 +13.25-18.24 -1.79 +0.41+1.86 = 42.7 SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-35 2021-2022 Academic year 3.2-5 MORE COMPLEX ANOVA MODELS Extending the formula to more complex ANOVA models is straightforward, for example, when increasing the number of factors in the experimental designs. When the number of factors is increased to factors A, B and C, then higher-order interactions appear, the three-order interaction A*B*C and 3 two-order interactions A*B, A*C, B*C and the main effects. Interpretation of model coefficients gets complex. In the designs of real experiments, the factors can be crossed or nested or both: they can all be easily incorporated. SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-36 2021-2022 Academic year 3.2-6 ANALYSIS OF COVARIANCE (ANCOVA MODELS)  ANCOVA models of analysis of covariance are mixed models that have dummy variables that represent levels of factors or interactions and continuous variables or covariates.  We are going to see ANCOVA models through an example without data, dealing with sociology and which is very intuitive, inspired by the Fox (1984) proposal: relation between income (Y) and level of education (X) among the white, oriental and black populations of the US (factor A, I=3). Model (M1): Factor–covariate interaction 1 2 3 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9 X Y Bl Bl Bl Bl Or Or Or Or Ne NeNe Ne FACTOR A 1 2 3 0123456789 0 1 2 3 4 5 6 7 8 9 X Y Bl Bl Bl Bl Or Or Or Or Ne Ne Ne Ne FACTOR A ikikiiik xY εθηαµ ++++= )( SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-37 2021-2022 Academic year 3.2-6. ANALYSIS OF COVARIANCE (ANCOVA MODELS) Model (M2): No factor–covariate interaction, no correlation between race and education. Model (M2): No factor–covariate interaction, correlation between race and education. 1 2 3 9876543210 9 8 7 6 5 4 3 2 1 0 X Y Ne Ne Ne Ne Or Or Or Or Bl Bl Bl Bl FACTOR A 1 2 3 87654321 7 6 5 4 3 2 X Y Ne Ne Ne Ne Or Or Or Or Bl Bl Bl Bl FACTOR A ik ikiik xY εηαµ +++= SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-38 2021-2022 Academic year 3.2-6. ANALYSIS OF COVARIANCE (ANCOVA MODELS) Model (M4) Income and education associated with but not affected by race Model (M4) Null model 1 2 3 3 4 5 6 3 4 5 6 X Y Bl Bl Bl Bl Or Or Or Or Ne Ne Ne Ne FACTOR A 1 2 3 3 4 5 6 3 4 5 6 X Y Bl Bl Bl BlOr Or Or Or Ne Ne Ne Ne ikikik xY εηµ ++= ikik Y εµ += SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-39 2021-2022 Academic year 3.2-6. ANALYSIS OF COVARIANCE (ANCOVA MODELS) Additive ANCOVA model (same slope) ik ikiik xY εηαµ +++= , has 5 (=1+3+1) parameters under baseline i=1, independent columns after forcing. 1 1 x1 1 0 0 x1 1 x1 X= 1 1 x 2 X R = 1 1 0 x 2 X= X R = 1 x 2 0 1 1 1 x3 1 0 1 x3 1 x3 0 1 1.1. 1 α η µ 3 α η µ η The simple regression model ikikik xY εηα ++= has 2 (=1+1) parameters. 2 α 3 α 2 α (M 2) (M 3) 0 1= α SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-40 2021-2022 Academic year 3.2-6. ANALYSIS OF COVARIANCE (ANCOVA MODELS) The ANCOVA model with interactions (different slope) ik ikiiik xY εθηαµ ++++= )( , has 8 (=1+3+4) parameters under baseline i=1 reparameterization leads to 6 (=1+2+1+2) independent columns after forcing. 0 0 1 1 x1 x1 1 0 0 x1 0 0 0 0 1 0 X= 1 1 x 2 x 2 X R = 1 1 0 x 2 x 2 0 1 0 0 1 0 0 1 1 x3 x3 1 0 1 x3 0 x3 0 1 0 0 1.1. 1 α η 1 θ 2 θ 1.1.1 µ 3 α η 2 θ 3 θ 2 α 3 α 2 α (M 1) 0 0 1 1 = = θ α SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-41 2021-2022 Academic year ANALYSIS OF COVARIANCE (ANCOVA MODELS) Manual example: Training type for runners (Dobson 1990) The data show the results obtained by 21 runners as three levels of a factor, representing three different methods of training, and an explanatory variable (covariate) that represents the score obtained before initiating the training. We want to compare the methods of training taking into account the different initial capacities (Dobson, 1990). Factor A Reply A 1 A 2 A 3 k=1 6 3 8 4 6 3 k=2 4 1 9 5 7 2 k=3 5 3 7 5 7 2 k=4 3 1 9 4 7 3 k=5 4 2 8 3 8 4 k=6 3 1 5 1 5 1 k=7 6 4 7 2 7 4 (y, x) y x y x y x 1 2 3 54321 9 8 7 6 5 4 3 X Y FACTOR A SIM course. Master in Data Science – FIBUPC Prof. Lídia Montero © Page 3.2-48 2021-2022 Academic year 3.2-7. ANALYSIS OF COVARIANCE: PRESTIGE EXAMPLE > options(contrasts=c("contr.sum","contr.sum")) > m1<-lm(prestige~type*income,data=Prestige[!is.na(Prestige$type),]) > summary(m1) Call:lm(formula =prestige~type*income, data=Prestige[!is.na(Prestige$type),]) Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3.524e+01 2.025e+00 17.399 < 2e-16 *** type1 -2.133e+01 2.729e+00 -7.818 8.59e-12 *** type2 2.369e+01 2.626e+00 9.020 2.63e-14 *** income 2.240e-03 3.334e-04 6.719 1.50e-09 *** type1:income 1.783e-03 4.616e-04 3.863 0.000208 *** type2:income -1.395e-03 3.621e-04 -3.852 0.000216 *** --- Residual standard error: 7.268 on 92 degrees of freedom Multiple R-squared: 0.8286, Adjusted R-squared: 0.8193 F-statistic: 88.94 on 5 and 92 DF, p-value: < 2.2e-16 𝑌𝑌 𝑖𝑖𝑖𝑖 =𝜇𝜇+𝛼𝛼𝑖𝑖+(𝜂𝜂+𝜃𝜃𝑖𝑖)𝑥𝑥𝑖𝑖𝑖𝑖 𝑤𝑤𝑤𝑤𝑤𝑤ℎ 𝛼𝛼1+𝛼𝛼2+𝛼𝛼3= 0 𝑎𝑎𝑛𝑛𝑛𝑛 𝜃𝜃1+𝜃𝜃2+𝜃𝜃3= 0 i=1: 𝑌𝑌 1𝑖𝑖 =𝜇𝜇+𝛼𝛼1+(𝜂𝜂+𝜃𝜃1)𝑥𝑥1𝑖𝑖 =(35.24 −21.33)+(0.0022 + 0.0018)𝑥𝑥1𝑖𝑖 i=2: 𝑌𝑌 2𝑖𝑖 =𝜇𝜇+𝛼𝛼2+(𝜂𝜂+𝜃𝜃2)𝑥𝑥2𝑖𝑖 =(35.24 + 23.69)+(0.0022 −0.0014)𝑥𝑥2𝑖𝑖 i=3: 𝑌𝑌 3𝑖𝑖 =𝜇𝜇+𝛼𝛼3+(𝜂𝜂+𝜃𝜃3)𝑥𝑥3𝑖𝑖 =(35.24 + 21.33 −23.69)+(0.0022 −0.0018 + 0.0014)𝑥𝑥3𝑖𝑖